-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use release javac option #10368
Use release javac option #10368
Conversation
Starting JDK 9, the javac executable can accept the --release option to specify against which Java SE release you want to build the project. Unlike the -source and -target options, the compiler will detect and generate an error when using APIs that don't exist in previous releases of Java SE. This option is available in maven-compiler-plugin since version 3.6. Using --release N is roughly equivalent to: - for N < 9: -source N -target N -bootclasspath <documented-APIs-from-N> - for N >= 9: -source N -target N --system <documented-APIs-from-N> For more details see https://openjdk.org/jeps/247. Signed-off-by: Federico Valeri <fedevaleri@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are supposed to be the benefits of this change?
The By default javac compiles against the most-recent version of the platform APIs. The compiled program can therefore accidentally use APIs only available in the current version of the platform. Instead the See this for a concrete example: https://www.baeldung.com/java-compiler-release-option#1-with-existing--source-and--target-option Another important point is that you can only use public APIs when compiling with |
Doesn't the article you linked suggest that this will not work as we do not have the older JDKs installed? |
No. It suggests that JDK 9 and later releases already contain the needed information to prevent you from accidental linking to symbols that did not exist in older JDK. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, let's try it. But if it breaks the release process I will never forget it 😉.
/azp run acceptance |
Azure Pipelines successfully started running 1 pipeline(s). |
I really hope not. I didn't know that flag but found out while working on Kafka, which also switched to using this from source and target some time ago. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Assuming it works ;-)
Type of change
Description
Starting JDK 9, the javac executable can accept the
--release
option to specify against which Java SE release you want to build the project. Unlike the-source
and-target
options, the compiler will detect and generate an error when using APIs that don't exist in previous releases of Java SE. This option is available in maven-compiler-plugin since version 3.6.Using
--release N
is roughly equivalent to:-source N -target N -bootclasspath <documented-APIs-from-N>
-source N -target N --system <documented-APIs-from-N>
For more details see https://openjdk.org/jeps/247.
Checklist