Skip to content

Fix and verify Java version compatibility of Java tools #26126

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

Closed
wants to merge 7 commits into from

Conversation

fmeum
Copy link
Collaborator

@fmeum fmeum commented May 22, 2025

Precompiled Java tools meant to run with the user-specified --java_{tool_,}runtime_version must only use Java 8 language features and APIs. Previously, these tools were compiled with --java_language_version=8, but had access to a JDK 21 as the bootclasspath. In fact, junitrunner used Stream#dropWhile, which isn't available in a JDK 8. Similarly, Java tools meant to run on the Java runtime provided by a Java (compilation) toolchain must only use Java 11 language features and APIs. This was the case, but they were in fact build with --java_language_version=8 and a JDK 21, just like the other tools.

This PR splits tools into two groups and enforces consistent Java language and bootclasspath runtime versions for them via --@rules_java//toolchains:incompatible_language_version_bootclasspath. Constants in //src:release_archive.bzl can be used to set the two minimum versions globally.

Related to #26100

@fmeum fmeum changed the title Fix and ensure Java 8/11 compatibility of prebuilt Java tools Fix and ensure Java 8 and 11 compatibility of prebuilt Java tools May 22, 2025
@fmeum fmeum force-pushed the fix-java-tools branch from c93d619 to 161cd83 Compare May 22, 2025 12:44
Prebuilt Java tools meant to run on the user-specified `--java_{tool_,}runtime_version` must only use Java 8 language features and APIs. Previously, these tools were compiled with `--java_language_version=8`, but had access to a JDK 21 as the bootclasspath. In fact, `junitrunner` used `Stream#dropWhile`, which isn't available in a JDK 8.
Similarly, Java tools meant to run on the Java runtime provided by a Java (compilation) toolchain must only use Java 11 language features and APIs. This was the case, but they were in fact build with `--java_language_version=8` and a JDK 21, just like the other tools, thus lacking validation for this property.

This PR splits tools into two groups and enforces consistent Java language and bootclasspath runtime for them via `--@rules_java//toolchains:incompatible_language_version_bootclasspath`. Constants in `//src:release_archive.bzl` can be used to set the two minimum versions globally.
@fmeum fmeum force-pushed the fix-java-tools branch from 161cd83 to 405fc89 Compare May 22, 2025 12:50
@@ -11,7 +10,7 @@ package(

licenses(["notice"]) # Apache 2.0

java_binary(
minimum_java_runtime_java_binary(
Copy link
Collaborator Author

@fmeum fmeum May 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's sometimes necessary to build this for a higher bytecode version, we could keep it a regular java_binary and wrap it in a transitioning filegroup.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @c-mita

@fmeum fmeum requested review from hvadehra and meteorcloudy May 22, 2025 12:55
@fmeum fmeum marked this pull request as ready for review May 22, 2025 12:55
@fmeum fmeum requested review from lberki and a team as code owners May 22, 2025 12:55
@github-actions github-actions bot added team-Rules-Java Issues for Java rules awaiting-review PR is awaiting review from an assigned reviewer labels May 22, 2025
@fmeum fmeum removed request for a team and lberki May 22, 2025 12:58
@fmeum fmeum changed the title Fix and ensure Java 8 and 11 compatibility of prebuilt Java tools Fix and ensure Java 8 and 11 compatibility o Java tools May 22, 2025
@fmeum fmeum changed the title Fix and ensure Java 8 and 11 compatibility o Java tools Fix and ensure Java 8 and 11 compatibility of Java tools May 22, 2025
@fmeum fmeum changed the title Fix and ensure Java 8 and 11 compatibility of Java tools Fix and verify Java 8 and 11 compatibility of Java tools May 22, 2025
@fmeum fmeum changed the title Fix and verify Java 8 and 11 compatibility of Java tools Fix and verify Java version compatibility of Java tools May 22, 2025
@fmeum
Copy link
Collaborator Author

fmeum commented May 22, 2025

CI is green after I fixed the bootstrap tests.

@fmeum fmeum requested review from hvadehra and c-mita May 23, 2025 20:22
@meteorcloudy meteorcloudy added awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally and removed awaiting-review PR is awaiting review from an assigned reviewer labels May 26, 2025
@github-actions github-actions bot removed the awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally label May 27, 2025
@fmeum fmeum deleted the fix-java-tools branch May 28, 2025 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-Rules-Java Issues for Java rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants