Skip to content
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

Merged
merged 1 commit into from
Jul 22, 2024
Merged

Use release javac option #10368

merged 1 commit into from
Jul 22, 2024

Conversation

fvaleri
Copy link
Contributor

@fvaleri fvaleri commented Jul 22, 2024

Type of change

  • Enhancement

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:

  • 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.

Checklist

  • Make sure all tests pass

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>
Copy link
Member

@scholzj scholzj left a 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?

@fvaleri
Copy link
Contributor Author

fvaleri commented Jul 22, 2024

What are supposed to be the benefits of this change?

The -source and -target options are not sufficient to safely compile to an older release.

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 --release flag automatically adds bootclasspath or system option to produce class files that will link against an implementation of the given platform version.

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 --release, which I think it's good to have, and doesn't seem to cause any problem in this project.

@fvaleri fvaleri added this to the 0.43.0 milestone Jul 22, 2024
@scholzj
Copy link
Member

scholzj commented Jul 22, 2024

Doesn't the article you linked suggest that this will not work as we do not have the older JDKs installed?

@fvaleri
Copy link
Contributor Author

fvaleri commented Jul 22, 2024

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.

Copy link
Member

@scholzj scholzj left a 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 😉.

@scholzj
Copy link
Member

scholzj commented Jul 22, 2024

/azp run acceptance

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@fvaleri
Copy link
Contributor Author

fvaleri commented Jul 22, 2024

Ok, let's try it. But if it breaks the release process I will never forget it 😉.

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.

Copy link
Member

@ppatierno ppatierno left a 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 ;-)

@scholzj scholzj merged commit 000b202 into strimzi:main Jul 22, 2024
15 checks passed
@fvaleri fvaleri deleted the release-option branch July 23, 2024 07:19
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