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

Uses --system <java11> when source_version set to "21" #227

Open
jeffalder opened this issue Sep 29, 2024 · 3 comments
Open

Uses --system <java11> when source_version set to "21" #227

jeffalder opened this issue Sep 29, 2024 · 3 comments
Assignees
Labels
P2 We'll consider to work on this in future. (Assignee optional) question Further information is requested

Comments

@jeffalder
Copy link

Setup:
rules_java 7.3.2
Bazel 6.5.0

Our codebase today compiles fine on Java 17. There are no issues. I am trying to switch my codebase to compile on Java 21 instead of Java 17. I've found most of the conversions, but one is lingering that I cannot decipher.

    default_java_toolchain(
        # elided
        source_version = java_version, # definitely 21
        target_version = java_version,
        # elided
    )

WORKSPACE:

load("@rules_java//java:repositories.bzl", "rules_java_dependencies", "rules_java_toolchains")
rules_java_dependencies()

# Register our toolchains first
register_toolchains(
    "//toolchains:javabase21_macos_x86_64",
    "//toolchains:javabase21_macos_aarch64",
    "//toolchains:javabase21_linux_x86_64",
    "//toolchains:java21_toolchain",
)

rules_java_toolchains()

# later

http_archive(
    name = "jdk21_linux_x86_64",
    build_file = "//toolchains:jdk_linux.BUILD", # this just extracts the files
    sha256 = "51fb4d03a4429c39d397d3a03a779077159317616550e4e71624c9843083e7b9",
    strip_prefix = "jdk-21.0.4+7",
    urls = ["https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.4%2B7/OpenJDK21U-jdk_x64_linux_hotspot_21.0.4_7.tar.gz"],
)

The javabase21_* and java21 are just renames of the toolchains that we defined using Java 17. I verified that the names link up corretctly in other code (omitted here).

When I attempt to compile anything on Java 21, the javac task adds the --system <java11> command-line parameter, where <java11> is the downloaded Zulu JDK 11. This means that compilation fails because it can't find JRE classes that were added in Java 17 (and working fine up until now). Let's ignore macos and just focus on Linux.

How can I "encourage" this to only use a Java 21 toolchain, either the local toolchain (if appropriate) or to download/install a toolchain?

@hvadehra
Copy link
Member

Toolchain configuration and selection is tricky to get right and debug. Could you please create and share a reproducer repository for this?

@hvadehra hvadehra self-assigned this Oct 17, 2024
@hvadehra hvadehra added question Further information is requested P1 I'll work on this now. (Assignee required) labels Oct 17, 2024
@jeffalder
Copy link
Author

@hvadehra - I will be happy to try. Do you have any quick tips on the best way to debug and troubleshoot this? Are there any specific diagnostic commands, debug dumps, or flags I can use to investigate? I'm happy to examine the output if it might be enlightening. Reconstructing our project to the point of failure will be extremely difficult due to the amount of Bazel code in the project.

@hvadehra
Copy link
Member

hvadehra commented Oct 17, 2024

You can try blaze build --nobuild --toolchain_resolution_debug=.* //foo:bar and see which toolchain gets selected and why the one you were expecting don't.

@hvadehra hvadehra added P2 We'll consider to work on this in future. (Assignee optional) and removed P1 I'll work on this now. (Assignee required) labels Oct 19, 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) question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants