jbang icon indicating copy to clipboard operation
jbang copied to clipboard

Use `--release` instead of `-source`/`-target` where appropriate

Open quintesse opened this issue 7 months ago • 2 comments

We use -source and -target compiler options in several places (eg https://github.com/maxandersen/jbang/blob/main/src/main/java/dev/jbang/source/buildsteps/CompileBuildStep.java#L74), we should use --release whenever using JDKs 9 and newer.

quintesse avatar Mar 24 '25 13:03 quintesse

I think i agree but can you remind me why?

For this specific instance enable preview wasn't introduced before java 12 afaik so we could probably just use --release but i feel there was a reason i used --source..but can't remember :)

maxandersen avatar Mar 25 '25 08:03 maxandersen

Well --release was only introduced in JDK 9 so we couldn't use it when supporting JDK 8. And the advantage seems to be that --source and --target only look at the source and bytecode level, but the JDK APIs might have changed as well. The --release option seems to somehow take that into account (this article explains it somewhat https://www.baeldung.com/java-compiler-release-option).

quintesse avatar Mar 25 '25 12:03 quintesse