You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Only use JAVA_HOME/@local_jdk as the default --javabase #5594
Since 849df36, bazel will always pick up a JDK from which javac or $JAVA_HOME in preference to an embedded one for @local_jdk//. I want to always use the embedded one instead. A startup option to do this would be fine.
Feature requests: what underlying problem are you trying to solve with this feature?
I version the bazel binary in my repository. I want this to fix the version of the JDK being used too, like it did before.
What operating system are you running Bazel on?
Debian Jessie amd64
What's the output of bazel info release?
release 0.15.0-peloton-201807111305+9c52124
This is 0.15.0 with a few local patches that aren't relevant.
Have you found anything relevant by searching the web?
Not quite. What I'm really looking for is a way to completely eliminate uses of any JDKs found via which javac or $JAVA_HOME or any other form of looking around on the system. Experimenting with --javabase=@embedded_jdk//:jdk --host_javabase=@embedded_jdk//:jdk just now, builds still fail on a machine with a weird (broken?) JDK exposed via which javac because that JDK is missing jar files in places bazel expects them.
I would also like a way to use the embedded JDK as the alternative so I have less stuff to version, but I wouldn't mind versioning a separate one via a bazel package too much.
As far as I can see, there are no user-accessible flags to change @local_jdk. src/main/cpp/blaze.cc always passes its own value for --default_system_javabase, and then everything else just uses that value. If there was some way to do that, I think it would be enough for my use case. I guess I could make my tools/bazel wrapper script download a fixed JDK, extract it, and set JAVA_HOME to point to it, but that seems like an awful lot of infrastructure to add to emulate something that used to just work. It's also a super trivial 1-line patch to make StartupOptions::GetSystemJavabase() return an empty string, and seems like it wouldn't be much harder to control that via a flag.
To confirm, is the request to support using the embedded JDK as the --javabase?
Not quite. What I'm really looking for is a way to completely eliminate uses of any JDKs found via which javac or $JAVA_HOME or any other form of looking around on the system.
To try to recap, there are three JDKs:
the JDK used to run Bazel itself. This is the startup --host_javabase (i.e. the LHS host_javabase)
the JDK used to run host tools that run during the build, e.g. javac. This is the build --host_javabase (i.e. the RHS host_javabase)
the JDK that the build is targeting, that is used to run any java_binary and java_tests that a build produces. This is the --javabase.
(1) and (2) now default to the embedded JDK (which is not the local JDK). They should be unaffected by JAVA_HOME and the presence of javac on the path.
(3) is the one that depends on JAVA_HOME / javac. You can set it explicitly using --javabase. --javabase=@embedded_jdk//:jdk doesn't work because Bazel doesn't support using JDK 9 as a target --javabase yet.
If you obtain a separate JDK 8, create a java_runtime rule and set the java_runtime.java_home attribute to the root of that JDK 8, and then set --javabase to the label of the java_runtime rule, that should guarantee that Bazel's behaviour is unaffected by JAVA_HOME etc.
Does that match what you're seeing?
I would also like a way to use the embedded JDK as the alternative so I have less stuff to version
This makes sense, but it isn't really the intended use-case for the embedded JDK. There's some discussion about shipping a minimal JDK that contains only what's need for the host_javabase use-case, which probably isn't what's wanted fro a target --javabase. It would be less fragile to explicitly choose the JDK version to target instead of using whatever version Bazel happens to be currently using.
There's some discussion happening about making it possible to configure host JDKs using remote repositories or similar, and it would probably be possible to use the same approach for target JDKs. So if you want the ability to version the host and target JDKs and avoid implicitly depending on the local JDK that'd be another way to approach it.
This original feature request (of using the embedded JDK as a target JDK) is not something we're likely to pursue for the reason I mentioned above: we want to make the embedded JDK image as a small as possible to reduce the installation size.
Even if I set --javabase and --host_javabase, builds still don't work on a machine where which javac finds a broken JDK. Is there some other flag that also needs to be set to completely avoid the system-installed JDK from affecting builds?
$ JAVA_HOME=/nonexistent /tmp/bazel-0.15.2-linux-x86_64 build //...WARNING: Running Bazel server needs to be killed, because the startup options are different.Starting local Bazel server and connecting to it........................ERROR: /x1/home/brian/.cache/bazel/_bazel_brian/9a14994a41429a580e5cd8b6f1b379ce/external/bazel_tools/tools/jdk/BUILD:181:1: no such package '@local_jdk//': Expected directory at /nonexistent but it does not exist. and referenced by '@bazel_tools//tools/jdk:jdk'ERROR: Analysis of target '//:main' failed; build aborted: Analysis failedINFO: Elapsed time: 6.264sINFO: 0 processes.FAILED: Build did NOT complete successfully (10 packages loaded) currently loading: @bazel_tools//src/tools/launcher ... (2 packages)
I was using the build flag because I didn't realize there was a startup one. What version of JDK is supported for the startup one? If I use a Java 8 one, it breaks because src/main/cpp/blaze.cc says TODO(b/109998449): only assume JDK >= 9 for embedded JDKs, and then adds a Java 9-only flag for passing to the JVM found via the --host_javabase startup flag. If I use a Java 9 one, then compilation via the java_* rules breaks because they don't support Java 9 JDKs yet. Neither the --host_javabase or --javabase build flags seem to make any difference whatsoever because @local_jdk fails to load either way.
Activity
cushon commentedon Jul 23, 2018
To confirm, is the request to support using the embedded JDK as the
--javabase?If the goal is to have
--javabaseversioned with your respository, have you considered versioning a separate JDK?brian-peloton commentedon Jul 23, 2018
Not quite. What I'm really looking for is a way to completely eliminate uses of any JDKs found via
which javacor$JAVA_HOMEor any other form of looking around on the system. Experimenting with--javabase=@embedded_jdk//:jdk --host_javabase=@embedded_jdk//:jdkjust now, builds still fail on a machine with a weird (broken?) JDK exposed viawhich javacbecause that JDK is missing jar files in places bazel expects them.I would also like a way to use the embedded JDK as the alternative so I have less stuff to version, but I wouldn't mind versioning a separate one via a bazel package too much.
As far as I can see, there are no user-accessible flags to change
@local_jdk. src/main/cpp/blaze.cc always passes its own value for--default_system_javabase, and then everything else just uses that value. If there was some way to do that, I think it would be enough for my use case. I guess I could make my tools/bazel wrapper script download a fixed JDK, extract it, and set JAVA_HOME to point to it, but that seems like an awful lot of infrastructure to add to emulate something that used to just work. It's also a super trivial 1-line patch to makeStartupOptions::GetSystemJavabase()return an empty string, and seems like it wouldn't be much harder to control that via a flag.cushon commentedon Jul 23, 2018
To try to recap, there are three JDKs:
startup --host_javabase(i.e. the LHS host_javabase)build --host_javabase(i.e. the RHS host_javabase)java_binaryandjava_teststhat a build produces. This is the--javabase.(1) and (2) now default to the embedded JDK (which is not the local JDK). They should be unaffected by
JAVA_HOMEand the presence ofjavacon the path.(3) is the one that depends on
JAVA_HOME/javac. You can set it explicitly using--javabase.--javabase=@embedded_jdk//:jdkdoesn't work because Bazel doesn't support using JDK 9 as a target--javabaseyet.If you obtain a separate JDK 8, create a
java_runtimerule and set thejava_runtime.java_homeattribute to the root of that JDK 8, and then set--javabaseto the label of thejava_runtimerule, that should guarantee that Bazel's behaviour is unaffected byJAVA_HOMEetc.Does that match what you're seeing?
This makes sense, but it isn't really the intended use-case for the embedded JDK. There's some discussion about shipping a minimal JDK that contains only what's need for the host_javabase use-case, which probably isn't what's wanted fro a target
--javabase. It would be less fragile to explicitly choose the JDK version to target instead of using whatever version Bazel happens to be currently using.cushon commentedon Jul 26, 2018
@philwo @buchgr FYI
There's some discussion happening about making it possible to configure host JDKs using remote repositories or similar, and it would probably be possible to use the same approach for target JDKs. So if you want the ability to version the host and target JDKs and avoid implicitly depending on the local JDK that'd be another way to approach it.
This original feature request (of using the embedded JDK as a target JDK) is not something we're likely to pursue for the reason I mentioned above: we want to make the embedded JDK image as a small as possible to reduce the installation size.
ittaiz commentedon Jul 26, 2018
cushon commentedon Jul 26, 2018
@ittaiz https://groups.google.com/d/topic/bazel-sig-jvm/noXlM1HOvVY/discussion
brian-peloton commentedon Jul 30, 2018
Even if I set --javabase and --host_javabase, builds still don't work on a machine where
which javacfinds a broken JDK. Is there some other flag that also needs to be set to completely avoid the system-installed JDK from affecting builds?brian-peloton commentedon Jul 30, 2018
Specifically, with this WORKSPACE:
And this BUILD:
This works (I'm doing this on a machine with a working JDK found via
which javac):But this fails:
cushon commentedon Jul 31, 2018
Are you setting the
--host_javabasebuild flag, or startup flag, or both?brian-peloton commentedon Aug 1, 2018
I was using the build flag because I didn't realize there was a startup one. What version of JDK is supported for the startup one? If I use a Java 8 one, it breaks because
src/main/cpp/blaze.ccsaysTODO(b/109998449): only assume JDK >= 9 for embedded JDKs, and then adds a Java 9-only flag for passing to the JVM found via the--host_javabasestartup flag. If I use a Java 9 one, then compilation via thejava_*rules breaks because they don't support Java 9 JDKs yet. Neither the--host_javabaseor--javabasebuild flags seem to make any difference whatsoever because@local_jdkfails to load either way.cushon commentedon Aug 1, 2018
The default
startup --host_javabaseis the embedded JDK, which is a JDK 10 in Bazel at head. It was JDK 9 until recently, and JDK 9 should still work.JDK 9 isn't supported as a target
--javabaseyet.If you use
bazel --host_javabase=<jdk 9> build ...that should work. If it doesn't, what error are you seeing?57 remaining items
Stop depending on deprecated @local_jdk//:langtools for tools.jar. (b…
Stop depending on deprecated @local_jdk//:langtools for tools.jar.
Stop depending on deprecated @local_jdk//:langtools for tools.jar.
Stop depending on deprecated @local_jdk//:langtools for tools.jar.
Stop depending on deprecated @local_jdk//:langtools for tools.jar.
Stop depending on deprecated @local_jdk//:langtools for tools.jar.
Stop depending on deprecated @local_jdk//:langtools for tools.jar.
Address Bazel's --incompatible_depset_is_not_iterable in build_defs.bzl
Stop depending on deprecated @local_jdk//:langtools for tools.jar.
Address Bazel's --incompatible_depset_is_not_iterable in build_defs.bzl
Stop depending on deprecated @local_jdk//:langtools for tools.jar.
No longer depend on "@bazel_tools//tools/jdk:jar"
Fix Bazel warnings (#3414)
Fix Bazel warnings (#3414)
sreev commentedon Nov 29, 2020
copying jdk tools.jar introduced bugs. refer to, bazelbuild/intellij#2164