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

Java 17 support #13965

Closed
shs96c opened this issue Sep 9, 2021 · 20 comments
Closed

Java 17 support #13965

shs96c opened this issue Sep 9, 2021 · 20 comments
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Rules-Java Issues for Java rules type: feature request

Comments

@shs96c
Copy link
Contributor

shs96c commented Sep 9, 2021

Description of the feature request:

Java 17 is expected to ship during the middle of September. It's the first LTS Java release since Java 11. Once it's out, teams using Bazel will want to migrate to Java 17, and Bazel needs to support this out-of-the-box.

While Bazel ships with toolchains to support different Java versions, there's nothing for java 17 yet (understandably), and it's not obvious how to hook in a custom JDK. The recommended way to do this is via the hermetic toolchains, but this feature only works in Bazel 5. Back-porting that to Bazel 4 seems complicated.

The alternative is a snippet much like:

build --host_javabase=@forked_jdk//java:java17-runtime
build --javabase=@forked_jdk//java:java17-runtime
build --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_java17
build --java_toolchain=@bazel_tools//tools/jdk:toolchain_java17

Here, @forked_jdk points to a custom JDK (assume it's something like "OpenJDK with some patches" such as Amazon Corretto)

The key missing piece is @bazel_tools//tools/jdk:toolchain_java17. The last toolchain_javaXX was for Java 11. If that was added, then we'd be able to make the jump to Java 17 quickly.

Feature requests: what underlying problem are you trying to solve with this feature?

People validating their builds on Java 17 need their build tool to properly support Java 17

@davido
Copy link
Contributor

davido commented Sep 11, 2021

Duplicate of #13416.

@gregestren
Copy link
Contributor

Also is #13966 different?

@shs96c
Copy link
Contributor Author

shs96c commented Sep 13, 2021

@gregestren This issue was about getting support for Java 17 at all in the tree. #13966 is about getting an official stable release of bazel that people can download and use it without needing to compile their own version of bazel.

@comius comius added P3 We're not considering working on this, but happy to review a PR. (No assignee) and removed untriaged labels Sep 15, 2021
@comius
Copy link
Contributor

comius commented Sep 15, 2021

P3, changes are very welcome and we will offer active support to any contributors.

@Jonpez2
Copy link
Contributor

Jonpez2 commented Sep 16, 2021

Step one here would presumably be to upgrade errorprone to the latest version, which includes a few jdk17 fixes. That will let us use jdk17 as the runtime, even if we can't use source/target versions.

How does one go about that?

Thanks!

@cushon
Copy link
Contributor

cushon commented Sep 20, 2021

I think Bazel has already been updated to the latest Error Prone release in 68e14b5, that part might just be blocked on a java_tools release.

Another problem is that turbine doesn't support all of the features up to Java 17 yet (e.g. records: #13924), I'm still working on that part.

@Jonpez2
Copy link
Contributor

Jonpez2 commented Sep 21, 2021 via email

@cushon
Copy link
Contributor

cushon commented Sep 26, 2021

@meteorcloudy could you add JDK 17 to the Bazel mirror (similar to #13274 (comment)) ?

cushon added a commit to cushon/bazel that referenced this issue Sep 26, 2021
cushon added a commit to cushon/bazel that referenced this issue Sep 27, 2021
@cushon
Copy link
Contributor

cushon commented Sep 27, 2021

The Java 17 test is failing with the following known issue in Error Prone 2.6.0, this needs a java_tools release that includes the updated to Error Prone 2.9.0 (68e14b5). @comius is that something you can help with?

public class Javac17Example {
       ^
  
     error-prone version: 2.6.0
     BugPattern: Immutable
     Stack Trace:
     java.lang.NoClassDefFoundError: com/sun/tools/javac/util/Filter

@comius
Copy link
Contributor

comius commented Sep 27, 2021

@hvadehra is handling release in bazelbuild/java_tools#51, there were some issues during the release, I didn't look into it yet, perhaps @cushon, you can help?

cushon added a commit to cushon/bazel that referenced this issue Sep 27, 2021
@hvadehra
Copy link
Member

@hvadehra is handling release in bazelbuild/java_tools#51, there were some issues during the release, I didn't look into it yet, perhaps @cushon, you can help?

java_tools v11.4 has been released

cushon added a commit to cushon/bazel that referenced this issue Sep 28, 2021
@cushon
Copy link
Contributor

cushon commented Sep 28, 2021

With #13416 and java_tools v11.4 I can build individual libraries that use Java 17 features.

Header compilation is still broken (#13924), that's fixed in turbine at head (google/turbine@ec67a6e). I'm waiting for another turbine change to land, and then I'll send an update for that.

bazel-io pushed a commit that referenced this issue Sep 29, 2021
google/turbine@cb60060

Required for #13965.

Closes #14059.

Signed-off-by: Philipp Wollermann <philwo@google.com>
bazel-io pushed a commit that referenced this issue Sep 30, 2021
#13965
#13416

Closes #14040.

PiperOrigin-RevId: 399931601
@cushon
Copy link
Contributor

cushon commented Sep 30, 2021

A quick update:

  • as of eb7bf8c, there's a Java 17 toolchain
  • Update turbine #14059 will update to a version of turbine that supports records and sealed classes
  • I have an internal review out to update ijar
  • the turbine and ijar changes will need another java_tools release

Once all of that happens, Bazel at head will have initial support for Java 17.

bazel-io pushed a commit that referenced this issue Oct 4, 2021
google/turbine@0b547dc

google/turbine@cb60060

Related to #13965.

Closes #14059.

Signed-off-by: Philipp Wollermann <philwo@google.com>
@comius
Copy link
Contributor

comius commented Oct 4, 2021

Hey @cushon are things ready for another java_tools release?

cc @hvadehra

@cushon
Copy link
Contributor

cushon commented Oct 4, 2021

@comius now that the ijar (26229fe) and turbine (69b4362) changes are merged, I think so.

@cushon
Copy link
Contributor

cushon commented Oct 4, 2021

@comius I have one more turbine improvement that would be nice to include in the next java_tools: #14076, as well as an internal change to ijar for sealed classes (cl/400867694)

@cushon
Copy link
Contributor

cushon commented Oct 6, 2021

@comius @hvadehra I think this is ready for another java_tools release

@cushon
Copy link
Contributor

cushon commented Oct 6, 2021

With #14089 patched in, simple Java 17 examples work when passing --java_language_version=17 --java_runtime_version=17 --tool_java_language_version=17 --tool_java_runtime_version=17.

I'd appreciate if anyone wants to try this out and report issues you find. We aren't using Java 17 much yet, so I don't have a lot of code to test against.

@cushon cushon closed this as completed Oct 6, 2021
@Jonpez2
Copy link
Contributor

Jonpez2 commented Oct 15, 2021

I just pulled latest bazel, updated the jdk version to 17, and everything built + tested fine.

(man I love bazel, the fact that I could do this so trivially is completel awesome)

Thank you all for doing this!

@eikemeier
Copy link

I'd appreciate if anyone wants to try this out and report issues you find. We aren't using Java 17 much yet, so I don't have a lot of code to test against.

It would be great if you could look into #14249

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Rules-Java Issues for Java rules type: feature request
Projects
None yet
Development

No branches or pull requests

8 participants