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

rules_java not respecting --tool_java_language_version/--tool_java_runtime_version for test_jar's as of at least 7.1.0 #165

Open
cjohnstoniv opened this issue Dec 23, 2023 · 2 comments
Labels
P2 We'll consider to work on this in future. (Assignee optional)

Comments

@cjohnstoniv
Copy link

When upgrading to Bazel 7.0.0, which upgraded my version of rules_java to 7.1.0, I have found that when building a test jar it has upgraded to using Java 21 despite passing the following in my .bazelrc file:

build --java_language_version=11
build --java_runtime_version=remotejdk_11
build --tool_java_language_version=11
build --tool_java_runtime_version=remotejdk_11

When building I can see that Java 21 is being used to compile the test jar in the error output with the path to java being external/remotejdk21_macos_aarch64/bin/java. I would expect this path to be a Java 11 JDK with the above options in the .bazelrc.

I have also tried upgrading to rules_java 7.3.2 and that also fails with the same issue.

@cjohnstoniv
Copy link
Author

minimum-project.zip

Attached is a minimum sample project to recreate the issue.

If you attempt to build the project you should get an error somewhere along the lines of:

ERROR: /home/cjohnstoniv/helm-farm/sample-java/BUILD:6:10: Building test-unit.jar (1 source file) failed: (Exit 1): java failed: error executing Javac command (from target //:test-unit) external/rules_java~7.1.0~toolchains~remotejdk21_linux/bin/java '--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED' '--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED' ... (remaining 19 arguments skipped)
src/test/java/hello/TestTest.java:10: error: ';' expected
        Fail me
               ^

The key piece of the error message is the: external/rules_java7.1.0toolchains~remotejdk21_linux/bin/java

I would expect this to be remotejdk11 based on the .bazelrc file.

@hvadehra
Copy link
Member

hvadehra commented Jan 8, 2024

This has come up before in #148 and bazelbuild/bazel#19934

The behavior changed in bazelbuild/bazel@37eb1d7 during platformization of the java rules. From what I've gathered, the motivation for fixing the java_runtime version was to avoid issues in the default case, i.e. when a local jdk is in use. cc @comius to correct me / add more colour.

As explained in bazelbuild/bazel#19934 (comment) using a newer runtime shouldn't matter in practice, as we still correctly use the source/target language level. If you must use a specific runtime version, please declare a custom default_java_toolchain specifying the needed value for java_runtime.

@hvadehra hvadehra added the P2 We'll consider to work on this in future. (Assignee optional) label Jan 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 We'll consider to work on this in future. (Assignee optional)
Projects
None yet
Development

No branches or pull requests

2 participants