jbang icon indicating copy to clipboard operation
jbang copied to clipboard

Can jBang support including maven filtered resources?

Open ottlinger opened this issue 2 years ago • 6 comments

Context

My project uses Maven and its ability to filter resources in order to inject properties/configuration parts into generated Java classes - these Java classes cannot be referenced from within JBang, thus making it impossible to use jBang.

Is there a plan to support additionally adding resources/classes or a workaround?

Link to example project

as a workaround the class could be taken as is (without filtered properties) in order for the project to compile with jBang.

ottlinger avatar Aug 16 '23 13:08 ottlinger

Trying to add the file as:

//FILES src/main/resources/Version.java=de.aikiit.spamprotector.util.Version.java

does not work:

$ jbang src/main/java/de/aikiit/spamprotector/AntiSpamApplication.java 
[jbang] [ERROR] Could not find 'de.aikiit.spamprotector.util.Version.java' when resolving 'src/main/resources/Version.java=de.aikiit.spamprotector.util.Version.java' in src/main/java/de/aikiit/spamprotector/AntiSpamApplication.java via Chain of [Trusted remote resource, Classpath resolver, File Resource resolver]
[jbang] Run with --verbose for more details

ottlinger avatar Aug 16 '23 13:08 ottlinger

You are trying to not only process the files filtering but you want it to be in the source folder for compilation.

Basically a mix of //FILES and //SOURCES.

We don't support that currently.

You can though include it with sources. But they won't be processed/filtered.

maxandersen avatar Aug 16 '23 19:08 maxandersen

closest fix at https://github.com/ottlinger/spamschutz/pull/307 using //SOURCES

we do have support for filtering via property keys in // commands; not in the full file.

We could do it on //FILES somehow; but not sure how to make it happen for //SOURCES as those are supposed to be compiled directly (no copying). Also we would need to do filtering before sources are calculated.

We would maybe have a magic property... //FILES ${jbang.filtered.sources}/=../resources/filtered/* ?

not sure yet; but I can see it be quite useful for even simple stuff - @quintesse thoughts ?

maxandersen avatar Aug 16 '23 20:08 maxandersen

@maxandersen thanks again for having a look at my issue - I've disabled using the maven-filtered class yesterday when you've made the proposed changes.

In https://github.com/ottlinger/spamschutz/commit/91121da88ecf9fa81abc3136afd433c3986187a5 I tried to play around with the copying mechanism, but due to the fact that the package does not match the file's location in the file tree I do not seem to be able to include my Version.java properly within the jbang-jar and get:

$ jbang src/main/java/de/aikiit/spamprotector/AntiSpamApplication.java --verbose
[jbang] Building jar for AntiSpamApplication.java...
/home/hirsch/Documents/workspace/spamschutz/src/main/java/de/aikiit/spamprotector/GUI.java:63: error: cannot find symbol
                        de.aikiit.spamprotector.util.Version.VERSION),
                                                    ^
  symbol:   class Version
  location: package de.aikiit.spamprotector.util
1 error
[jbang] [ERROR] Error during compile
[jbang] Run with --verbose for more details

Is there a way to include a specific file and somehow put it in the correct package hierarchy?

ottlinger avatar Aug 18 '23 08:08 ottlinger

you need to use a path separator not package separator.

i.e. //FILES de/aikiit/spamprotector/util/Version.java=../../../../resources/filtered/Version.java

but wont help you much as this just put a .java file in your jar - it won't be compiled.

maxandersen avatar Aug 18 '23 10:08 maxandersen

Thanks for the clarification, unfortunately I'm unable to use jbang then (at the moment :)). Thanks again for your help.

ottlinger avatar Aug 20 '23 13:08 ottlinger