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

Where's the documentation? How do I force to use the local JVM? #179

Closed
grepwood opened this issue Mar 20, 2024 · 2 comments
Closed

Where's the documentation? How do I force to use the local JVM? #179

grepwood opened this issue Mar 20, 2024 · 2 comments

Comments

@grepwood
Copy link

grepwood commented Mar 20, 2024

Hi,

Before anyone asks, I'm using Bazel 7.0.0 with rules_java 7.4.0 and java_tools 13.4.

I wanted to know how do I force this library to use only the local JVM, because the build system I have has a strict "one version of every tool" policy. One Python, one Golang, one GCC, one NodeJS, one Scala, one Java, etc.

The reason why I wanted this, is because the codebase I tend to is not ready to be compiled with Java 21, which rules_java 7.4.0 seems to be using for literally everything.

So I wanted to read the documentation. Finding out there is none, I started reading the code - comments may lie, but code never lies. I'm having a really hard time understanding how the compile warnings we get only in Java 21 manage to bleed into Java 17 and 11 once I patch this line to reflect our wishes - https://github.com/bazelbuild/rules_java/blob/7.4.0/toolchains/default_java_toolchain.bzl#L95

Warnings during Java compilation are treated as errors. Please don't ask me why.

Also the reason why I expected to find the documentation in this repository is because almost every Bazel rules does this. rules_java is one of the exceptions and outliers to this unwritten trend. The majority of Bazel rules have this kind of documentation and therefore set up some kind of expectation in the end users, I'm afraid.

There's a million options in Bazel to change the Java version and none of them seem to work. They are no-ops at best. At worst, they are deprecated so badly that merely having them in .bazelrc will make Bazel refuse to get up. This is a separate problem and I hope to address this in a separate issue if I'm still bothered enough to care about it.

I'm now writing this issue and I'm like "someone will be like ohhhhhhh did you use the search function? we have the docs here, there's always someone like that". OK I tried these links:

Can someone who is more knowledgeable in these matters please tell me how can I solve this issue? How can I tell rules_java and Bazel and everything in the goddamn monorepo that I want to use a local JVM?

@hvadehra
Copy link
Member

https://bazel.build/reference/be/java?hl=pl it's just a page that says "8024249765089568664" - wtf?

cc @meteorcloudy looks like some of the translated pages are broken.

How can I tell rules_java and Bazel and everything in the goddamn monorepo that I want to use a local JVM?

The critical bit is there are generally two java runtimes, one in the target config (running your compiled java code) and one for the exec/tool config (running java tools as part of the build itself). See bazelbuild/bazel#19934 (comment) for more.

By default, Bazel uses the local_jdk as the target runtime, and a remote_jdk for exec/tool. This is because using a local jdk for tools would interact badly with remote execution. More generally, using a local jdk is best avoided (even for the target config), since it breaks hermeticity. If you absolutely must, see bazelbuild/bazel#21752 (comment)

fwiw the docs you're looking for might be: https://bazel.build/docs/bazel-and-java. Apologies for it not being more easy-to-find.

@grepwood
Copy link
Author

Thank you @hvadehra! And sorry for being so sour in the original post

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

No branches or pull requests

2 participants