Skip to content

Conversation

@maxandersen
Copy link
Collaborator

alternative/replacement of #2143

in #2143 it was suggested to force add "//JAVA 25+" when compact source enabled (automatically enabled when Java > 25) but I turned it down as it was resulting in inconsistent behavior.

Since then I myself been caught by having done jbang init --java 25 hello.java and then when running ./hello.java it didn't work because my environments java was less than Java 25.

so this PR suggests introducing a requestedJavaVersion property which will be set to null if no specific java version requested; and other set to the raw string of the arg value in --java <arg>

Then use that to generate //JAVA ${requestedJavaVersion} if requested version is present, and in the case of compact source files will get //JAVA 25+ if you did not request a specific java file...meaning no matter how you get a compact source file - it will always have at least //JAVA 25+ in it OR what you requested using --java <arg>

In addition I updated the compact source to use IO.println() to be able to cut out the import line.

///usr/bin/env jbang "$0" "$@" ; exit $?
//JAVA 25+

void main(String... args) {
    IO.println("Hello World");
}

I also added {#if requestedJavaVersion} //JAVA {requestedJavaVersion} {/if}

to the templates I could see it being meaningful.

wdyt @wfouche and @quintesse - I think this should make us all more happy than annoyed ;)

@maxandersen
Copy link
Collaborator Author

btw. yes - this is up to the individual templates wether they want to honor this or not. but we already have templates setting specific java versions so i dont think there is much way around this.

@wfouche
Copy link
Contributor

wfouche commented Sep 13, 2025

I like this change, and it is future proof. :-)

@quintesse
Copy link
Contributor

I think it's a good compromise. Merge it! :-)

@maxandersen maxandersen merged commit 17d8557 into jbangdev:main Sep 14, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants