feat: requestedJavaVersion honored by init templates #2206
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.javaand then when running./hello.javait didn't work because my environments java was less than Java 25.so this PR suggests introducing a
requestedJavaVersionproperty 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.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 ;)