-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Java 9 should be supported #3410
Comments
Sadly, this will have to wait until we get proper support for Java 9, which means quite a bit of work internally. /cc @cushon |
@lberki can you quantify "quite a bit of work" in term of time frame? Google is usually years behind bumping its internal Java tool chain to very recent JDK after the day it was released. Final Java 9 release was previously scheduled to July 2017 and was postponed to September 2017. My expectation would be that the day, Java 9 final is released, Bazel supports it. Your comment sounds like, it could happen, that Bazel users would have to wait for months (or years?) for that to happen. |
It will happen and definitely not within years, but also probably not sooner than months. It's just another thing we have to fit into our schedule and unfortunately, it's not amenable to being done by non-Googler contributors since we need to make sure that it integrates well with our internal repository. We can shuffle around priorities if there is good reason but my best understanding is that Java 9 is not a hard blocker for anyone, at least for the time being. |
Hi all, I posted a question about the interest in java 9 on bazel-discuss. It also contains an update on when we might support it. Can you comment there about your expectations? Thanks! |
I'd echo @davido's comment above, and @dfabulich's experience: bazel must, at the very least, be able to run on a system with java 9 installed, and that needs to happen ASAP. Compiling to java 9 is less urgent. Early Q1 2018 might be okay, but end of Q1 is too long --- I want to start taking advantage of new language features RSN. I guess I could specify a java_toolchain to make this work as a hack, but I'd need to be able to do that on a per-clone basis (so I can work on my Mac and have CI on a linux box) Actually taking advantage of java modules would be a killer feature, but given the slow adoption of java 8, it's the least pressing feature. |
@shs96c does this mean supporting |
Something else. If you export JAVA_HOME=<jdk9>, Bazel refuses to start, even when you install a version of Bazel that embeds its own JVM.
…-Dan
On Sep 25, 2017, at 6:46 PM, Liam Miller-Cushon ***@***.***> wrote:
bazel must, at the very least, be able to run on a system with java 9 installed
@shs96c <https://github.com/shs96c> does this mean supporting blaze build --host_javabase=<jdk9> ..., or something else?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#3410 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AAF3lhlicrZcj9wSmx8sGJyFL9jMzhR1ks5smFeHgaJpZM4Ob8zC>.
|
I think this diff should fix Bazel start:
The next failure if I try to use JDK9 with custom built
I think, that this is defined here: https://github.com/bazelbuild/bazel/blob/master/tools/jdk/BUILD#L110-L116.
If I remove them:
and rebuild bazel with JDK8, and try again to use JDK8 to build one single java source, I get this failure now:
To reproduce, bazel_printy is here: [1]. The CL is here: [2]. |
What is the status here? I'm not eager to use wrapper scripts on |
As mentioned in my previous comments: it will take years, for Java 9 to be supported in Bazel. |
In Homebrew, we're doing this:
It would be nice if this were something |
Can we separate out the issues of bazel compiling Java 9 source from bazel running under jvm 9? This seems to cover both, but it seems like it should be possible to run bazel with embedded jdk under jvm 9. I propose reopening #3789 to track the running under jvm 9 issue. |
I have gotten a bazel build that works for both JDK8 and JDK9. I created the fork is here: https://github.com/hhclam/bazel/commits/java9. The fork has only one commit with very little code change: hhclam@64212c8. It's fair to say that it is tricky but Bazel is mostly capable to run in both JDKs. If you build bazel from source with a JDK8 with the fork, e.g.: The resultant bazel binary should work with both JDK8 and JDK9. For JDK9 specifically you have to run Bazel with: Worker process works with this toolchain. However Turbine (java header compilation) is disabled. The neat things like strict deps and error prone are still intact. The major non-code change in this commit is to define a new toolchain called "jdk9" which does not have -Xbootclasspath/p and does not use the javac that is bundled with Bazel. It could work with the Bazel-bundled javac since it is a build from OpenJDK 9 but it's confusing. I went even further to stripping the javac (com.sun) classes from the deploy jar to provide a new JavaBuilder without javac and JDK internal classes. The minor code change is to suppress warnings from jigsaw. The major code change is to accept --patch-module, --add-modules and --add-exports for "javacopts" for java_* and "misc" for java_toolchain. This is needed because a lot of existing code uses JDK internals. This patch should work with a simple Java application. I was able to build a large-ish swagger application with this patch. The real pain being jigsaw complaining about javax.annotation and jsr305. This affects a lot of generated code including grpc (which uses javax.annotation.Generated). The solution is to create your own java_toolchain (make a copy from the jdk9 toolchain) and then add --patch-module and --add-modules to patch the javax.annotation module with the jsr305 jar. |
@hhclam Thanks, this is very promising! I started to use your Bazel patch to build Gerrit Code Review, on Java 9, but it didn't really worked. So far I discovered two problems:
For the former problem:
I filed this issue: google/error-prone#850, and was able to turn off EP/Bazel integration with javacopt For the latter
but then annotation processor was failing with a NPE on an innocent I extracted this reproducer from gerrit and verified, that the reproducer can be built with Java 9, with Maven's |
@davido The issue you are hitting is not Bazel specific but caused by jigsaw. However there's no easy way to solve it in Bazel.
I tested your example that this Bazel build passed. However you'll probably hit another issue with the javax.annotation package. This thread has a lot of relavent information: google/dagger#880 I think to summarize this is: a lot of 3rd party libraries have issue with javax.annotation (potentially other packages as well) due to jigsaw and Bazel provides no way to workaround that easily. |
@hhclam At least auto-value specific problem can be easily avoided by adding dependency on javax.annotation-api to The next issue, as you noticed, is gerrit -> rules_closure -> dager related: [2]. Gerrit has two UIs: GWT and JS, so I disabled JS UI for now: [3] and was able to build GWT UI based gerrit with Java 9. This is already not bad, besides that, trying to initialize with Java 9 built gerrit site is failing with NPE: [4]. |
The NPE issue is with auto-value I believe. I don't know what version of gerrit you're building as the latest revision seems to being using it's own Nullable. You might find more helpful information here: google/auto#283. This is another issue with JDK9 caused by jigsaw and javax.annotation. |
Awsome! Is there a way to do select based on the java version? |
Targeting a specific JDK version usually involves setting |
On bazel master (db65f80) Java 9 support seems to be broken again: [1].
I think it worked already, or should i pass in addition to Java 9 specific options: |
AFAIK the combination of Also, a stock javac 9 with
|
Except that I don't specify "-source 8 -target 8" in any place. All I say in JGit is:
And javac complaining that: option --add-modules not allowed with target 1.8. Or am I invoking the java 9 wrong now (on Bazel master)? I'm saying that:
|
OK, figured it out, I must specify
|
Just passing by a unrelated search brought me here. You may find my Java 9 Cheat Sheet of interest. Also if you have any specific build issues I may be able to help. I am not familiar with bazelbuild, but I have some 800-1K packages built from source under Java 9. Albeit in abnormal Gentoo ways.... Otherwise sorry for unrelated noise! |
For the Java EE stuff like |
Fixes: bazelbuild#3410, bazelbuild#4709. To build bazel with Java 9 issue: $ bazel --host_javabase=/usr/lib64/jvm/java-9-openjdk build \ --javacopt='--release 9' \ --java_toolchain=@bazel_tools//tools/jdk:toolchain_jdk9 \ src:bazel This still doesn't work: [1]. * [1] http://paste.openstack.org/show/694736 Change-Id: Ic529e222344dc894e9d6b853a9551c7a19a52697
Fixes: bazelbuild#3410, bazelbuild#4709. To build bazel with Java 9 issue: $ bazel --host_javabase=/usr/lib64/jvm/java-9-openjdk build \ --javacopt='--release 9' \ --java_toolchain=@bazel_tools//tools/jdk:toolchain_jdk9 \ src:bazel This still doesn't work due to gRpc dependency on Java 8 specific @javax.annotation.Generated annotation: [1]. [1] grpc/grpc-java#3633 Change-Id: Ic529e222344dc894e9d6b853a9551c7a19a52697
Fixes: bazelbuild#3410. To build bazel with Java 9 issue: $ bazel --host_javabase=/usr/lib64/jvm/java-9-openjdk build \ --javacopt='--release 9' \ --java_toolchain=@bazel_tools//tools/jdk:toolchain_jdk9 \ src:bazel This still doesn't work: [1]. * [1] http://paste.openstack.org/show/694736 Change-Id: Ic529e222344dc894e9d6b853a9551c7a19a52697
See bazelbuild#3410, bazelbuild#4812 Change-Id: Idd4adad7d48899c3b6de635d417446b71ba44afa
See bazelbuild#3410, bazelbuild#4812 Change-Id: Idd4adad7d48899c3b6de635d417446b71ba44afa
See bazelbuild#3410, bazelbuild#4812 Change-Id: Idd4adad7d48899c3b6de635d417446b71ba44afa
It seems, that on most recent Bazel master (b7d65cd), with only two small tweaks: [1] I'm able to build bazel itself with Java 9. However, if I try to build gerrit with that version of bazel on Java 9 with this CL: [2], it's failing to build java headers in
The [1] https://bazel-review.googlesource.com/q/topic:support-build-bazel-with-java-9 |
@cushon Thanks for the quick fix. It works now. The only opened issues for full JDK 9 support in Bazel are:
[1] grpc/grpc-java#3633 |
@cushon It seems, that once the alternative fix for gRpc's |
Bazel at head can now build itself with a JDK 9 host_javabase, and the tentative plan is still to ship this in 0.14.0:
|
The default Bazel binaries now include an embedded JDK 9, which is used as the default javabase for Bazel itself and for host tools ( The default language level is still Java 8 for now, but to use the Java 9 language level you can use:
If you encounter any problems using Java 9 with Bazel, please file additional bugs. |
java_toolchain requires a bootstrap classpath, including rt.jar, but Java 9 no longer has rt.jar or anything like that.
java_toolchain has to be rethought for Java 9 support
The text was updated successfully, but these errors were encountered: