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

Toolchain downloads frequently failing #7492

Closed
cpovirk opened this issue Oct 26, 2024 · 3 comments · Fixed by #7589
Closed

Toolchain downloads frequently failing #7492

cpovirk opened this issue Oct 26, 2024 · 3 comments · Fixed by #7589
Assignees
Labels
P2 package=general type=defect Bug, not working as expected

Comments

@cpovirk
Copy link
Member

cpovirk commented Oct 26, 2024

I've had multiple PRs recently that have failed testing because of trouble downloading a JDK. Here's the most recent example, which downloaded 11 but failed on 23, but note that I think I've seen failures for 11 and have definitely seen a failure for 8:

[INFO] --- toolchains:4.5.0:toolchain (download-11) @ guava ---
[INFO] Required toolchain: jdk [ vendor='zulu' version='11' ]
[INFO] Begin to install JDK 11
[INFO] Download zulu11.76.21-ca-jdk11.0.25-linux_x64.tar.gz from https://cdn.azul.com/zulu/bin/zulu11.76.21-ca-jdk11.0.25-linux_x64.tar.gz
[INFO] Extract zulu11.76.21-ca-jdk11.0.25-linux_x64.tar.gz
[INFO] JDK installed: /home/runner/.m2/jdks/zulu11.76.21-ca-jdk11.0.25-linux_x64
[INFO] 
[INFO] --- toolchains:4.5.0:toolchain (download-23-and-surefire-version) @ guava ---
[INFO] Required toolchain: jdk [ vendor='zulu' version='23' ]
[INFO] Begin to install JDK 23
[INFO] Download zulu23.30.13-ca-jdk23.0.1-linux_x64.tar.gz from https://cdn.azul.com/zulu/bin/zulu23.30.13-ca-jdk23.0.1-linux_x64.tar.gz
[INFO] Extract zulu23.30.13-ca-jdk23.0.1-linux_x64.tar.gz
Error:  Failed to download and install JDK
org.codehaus.plexus.archiver.ArchiverException: Error while expanding /home/runner/.m2/jdks/zulu23.30.13-ca-jdk23.0.1-linux_x64.tar.gz
    at org.codehaus.plexus.archiver.tar.TarUnArchiver.execute (TarUnArchiver.java:124)
    at org.codehaus.plexus.archiver.tar.TarUnArchiver.execute (TarUnArchiver.java:88)
    at org.codehaus.plexus.archiver.AbstractUnArchiver.extract (AbstractUnArchiver.java:151)
    at org.apache.maven.plugins.toolchain.FoojayService.extractArchiveFile (FoojayService.java:206)
    at org.apache.maven.plugins.toolchain.FoojayService.downloadAndExtract (FoojayService.java:166)
    at org.apache.maven.plugins.toolchain.FoojayService.downloadAndExtractJdk (FoojayService.java:94)
    at org.apache.maven.plugins.toolchain.ToolchainMojo.autoInstallJdk (ToolchainMojo.java:233)
    at org.apache.maven.plugins.toolchain.ToolchainMojo.selectToolchain (ToolchainMojo.java:195)
    at org.apache.maven.plugins.toolchain.ToolchainMojo.execute (ToolchainMojo.java:111)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
    at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
    at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
    at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:906)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:206)
    at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:103)
    at java.lang.reflect.Method.invoke (Method.java:580)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:255)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:201)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:361)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:314)
    at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:103)
    at java.lang.reflect.Method.invoke (Method.java:580)
    at org.apache.maven.wrapper.BootstrapMainStarter.start (BootstrapMainStarter.java:52)
    at org.apache.maven.wrapper.WrapperExecutor.execute (WrapperExecutor.java:161)
    at org.apache.maven.wrapper.MavenWrapperMain.main (MavenWrapperMain.java:73)
Caused by: java.io.EOFException: Unexpected end of ZLIB input stream
    at java.util.zip.InflaterInputStream.fill (InflaterInputStream.java:266)
    at java.util.zip.InflaterInputStream.read (InflaterInputStream.java:175)
    at java.util.zip.GZIPInputStream.read (GZIPInputStream.java:128)
    at java.io.BufferedInputStream.fill (BufferedInputStream.java:291)
    at java.io.BufferedInputStream.read1 (BufferedInputStream.java:347)
    at java.io.BufferedInputStream.implRead (BufferedInputStream.java:420)
    at java.io.BufferedInputStream.read (BufferedInputStream.java:399)
    at org.apache.commons.compress.archivers.tar.TarArchiveInputStream.read (TarArchiveInputStream.java:873)
    at java.io.InputStream.read (InputStream.java:220)
    at org.codehaus.plexus.util.IOUtil.copy (IOUtil.java:189)
    at org.codehaus.plexus.util.IOUtil.copy (IOUtil.java:175)
    at org.codehaus.plexus.archiver.AbstractUnArchiver.extractFile (AbstractUnArchiver.java:372)
    at org.codehaus.plexus.archiver.tar.TarUnArchiver.execute (TarUnArchiver.java:114)
    at org.codehaus.plexus.archiver.tar.TarUnArchiver.execute (TarUnArchiver.java:88)
    at org.codehaus.plexus.archiver.AbstractUnArchiver.extract (AbstractUnArchiver.java:151)
    at org.apache.maven.plugins.toolchain.FoojayService.extractArchiveFile (FoojayService.java:206)
    at org.apache.maven.plugins.toolchain.FoojayService.downloadAndExtract (FoojayService.java:166)
    at org.apache.maven.plugins.toolchain.FoojayService.downloadAndExtractJdk (FoojayService.java:94)
    at org.apache.maven.plugins.toolchain.ToolchainMojo.autoInstallJdk (ToolchainMojo.java:233)
    at org.apache.maven.plugins.toolchain.ToolchainMojo.selectToolchain (ToolchainMojo.java:195)
    at org.apache.maven.plugins.toolchain.ToolchainMojo.execute (ToolchainMojo.java:111)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
    at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
    at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
    at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:906)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:206)
    at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:103)
    at java.lang.reflect.Method.invoke (Method.java:580)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:255)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:201)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:361)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:314)
    at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:103)
    at java.lang.reflect.Method.invoke (Method.java:580)
    at org.apache.maven.wrapper.BootstrapMainStarter.start (BootstrapMainStarter.java:52)
    at org.apache.maven.wrapper.WrapperExecutor.execute (WrapperExecutor.java:161)
    at org.apache.maven.wrapper.MavenWrapperMain.main (MavenWrapperMain.java:73)
Error:  No toolchain matched from 2 found for toolchainType jdk
[INFO] Required toolchain: jdk [ vendor='zulu' version='21' ]
[INFO] Found matching toolchain for toolchainType jdk: JDK[/opt/hostedtoolcache/Java_Zulu_jdk/21.0.5-11/x64]
Error:  Cannot find matching toolchain definitions for the following toolchain types:
jdk [ vendor='zulu' version='23' ]

(Aside: GitHub is inserting Markdown when I copy and paste directly from the Actions results, possibly to link to anchors in that page? Not that that would work inside the code block that I'm pasting into. I ended up pasting into a plain-text window first and then copying and pasting again.)

The automatic toolchain downloads are nice, but it would probably be more reliable for CI to download all the toolchains we need with setup-java. (That would likely also be faster, as noted in internal bug 334979149.) The trick would be ensuring that we still use the toolchain that we want for (a) testing and (b, possibly less important) running Maven itself. Error Prone has this worked out by being careful about the order in which they list their downloaded toolchains and then (I'm guessing) by configuring maven-surefire-plugin more directly than we do.

(We could still keep the toolchain plugin for local builds. It's much nicer for users than if they have to download various toolchains themselves.)

@cpovirk cpovirk added P3 no SLO package=general type=defect Bug, not working as expected labels Oct 26, 2024
@ben-manes
Copy link
Contributor

Also consider trying to ensure that you are leveraging the hosted tool cache which avoids downloading if you use one of the pre-installed jdks (temurin 8, 11, 17, 21). You can also use composite github actions for reuse, optionally across repositories, if you find a common setup is helpful (e.g. I wrangle all of my jdk versions in this action)

@cpovirk
Copy link
Member Author

cpovirk commented Dec 12, 2024

Slightly different stack trace today:

java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
    at jdk.internal.util.Preconditions.outOfBounds (Preconditions.java:64)
    at jdk.internal.util.Preconditions.outOfBoundsCheckIndex (Preconditions.java:70)
    at jdk.internal.util.Preconditions.checkIndex (Preconditions.java:266)
    at java.util.Objects.checkIndex (Objects.java:361)
    at java.util.ArrayList.get (ArrayList.java:427)
    at com.google.gson.JsonArray.get (JsonArray.java:203)
    at org.apache.maven.plugins.toolchain.FoojayService.parseFileNameAndDownloadUrl (FoojayService.java:145)
    at org.apache.maven.plugins.toolchain.FoojayService.downloadAndExtractJdk (FoojayService.java:82)

@cpovirk cpovirk added P2 and removed P3 no SLO labels Jan 2, 2025
@cpovirk cpovirk self-assigned this Jan 2, 2025
copybara-service bot pushed a commit that referenced this issue Jan 2, 2025
…=21` to set the Java version for tests, and do so in CI. (The property value still _defaults_ to the JDK that you use to run Maven, so passing the flag is not _necessary_.)

This lets us use whatever Java version we want\[1\] for executing Maven itself—and thus for executing any plugins that aren't toolchain-aware. (I even hacked up our toolchain configuration to run tests under Java 24, and it worked.) I've changed our CI to do that, too, by always using Java 23. (This makes the explicit choice of Java 23 for _javac_ redundant under CI, as well as on our Google workstations. However, it can be useful for anyone who builds Guava locally while having an older JDK as the default version.)

Notably, that means that we can use a new version (like Java 23) for running the GWT plugin, which lets us upgrade to GWT 2.12.1 (cl/711417161), which uses an Eclipse compiler with bytecode version 55 (Java 11)\[2\]. (This means that users who build `guava-gwt` locally with Java 8 will need to [upgrade their build JDK to at least Java 11](https://github.com/google/guava/issues/6549)—or skip building `guava-gwt` if they don't need it.)

That GWT upgrade is in turn necessary in order for us to be able to use use [JSpecify annotations](jspecify/jspecify#239) from our GWT artifact.

In theory, this could also prepare us for further changes, like more easily running tests under multiple versions during our release process (in addition to how we already do so for CI), though there are already other ways of doing that by hacking up our release script or `pom.xml`. And I'm not sure that I'd really want to do that, anyway. (See also some notes that I've added to cl/639128020.)

I also did some related cleanup:

- Our `--no-module-directories` configuration probably became Just Wrong back in cl/655647768: It should be based on the version that we use to build Javadoc (which is currently always 11), not the version that Maven is running under. It probably mostly doesn't matter because we probably mostly don't try to run Javadoc under other versions, but I'd like to be able to do so, so this is a step forward.
- `-Djava.security.manager=allow` is not necessary now that we've cleaned up our usages of `SecurityManager`. (And that's fortunate, as it seems difficult to [active a profile based on a range of values of an arbitrary "my test JRE version" property](https://issues.apache.org/jira/browse/MNG-3328), as opposed to activate it based on the JDK that Maven is running under.)

I expect that this CL is going to fail Gradle integration testing because that testing (when last I checked) required Java 11. I'll try to figure that out once I see the full CI results, which may well reveal bigger problems.

Fixes #7492 (by making `setup-java` download all the toolchains that we need)

\[1\] I mean, I suspect that Maven support lags new JDKs somewhat, and I've seen problems with other versions (as documented in cl/488902996). But at least we don't have to use the same Java version for executing Maven itself as we do for executing tests.

\[2\] That was causing this error:

```
[INFO] --- gwt:2.10.0:compile (gwt-compile) @ guava-gwt ---
Error: [ERROR] Unexpected internal compiler error
[INFO] java.lang.UnsupportedClassVersionError: org/eclipse/jdt/internal/compiler/classfmt/ClassFormatException has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
[INFO] 	at java.lang.ClassLoader.defineClass1(Native Method)
[INFO] 	at java.lang.ClassLoader.defineClass(ClassLoader.java:757)
[INFO] 	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
[INFO] 	at java.net.URLClassLoader.defineClass(URLClassLoader.java:473)
[INFO] 	at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
[INFO] 	at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
[INFO] 	at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
[INFO] 	at java.security.AccessController.doPrivileged(Native Method)
[INFO] 	at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
[INFO] 	at java.lang.ClassLoader.loadClass(ClassLoader.java:419)
[INFO] 	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
[INFO] 	at java.lang.ClassLoader.loadClass(ClassLoader.java:352)
[INFO] 	at com.google.gwt.dev.javac.CompilationStateBuilder.doBuildFrom(CompilationStateBuilder.java:488)
[INFO] 	at com.google.gwt.dev.javac.CompilationStateBuilder.buildFrom(CompilationStateBuilder.java:464)
[INFO] 	at com.google.gwt.dev.cfg.ModuleDef.getCompilationState(ModuleDef.java:426)
[INFO] 	at com.google.gwt.dev.Precompile.validate(Precompile.java:145)
[INFO] 	at com.google.gwt.dev.Compiler.compile(Compiler.java:184)
[INFO] 	at com.google.gwt.dev.Compiler.compile(Compiler.java:143)
[INFO] 	at com.google.gwt.dev.Compiler.compile(Compiler.java:132)
[INFO] 	at com.google.gwt.dev.Compiler$1.run(Compiler.java:110)
[INFO] 	at com.google.gwt.dev.CompileTaskRunner.doRun(CompileTaskRunner.java:55)
[INFO] 	at com.google.gwt.dev.CompileTaskRunner.runWithAppropriateLogger(CompileTaskRunner.java:50)
[INFO] 	at com.google.gwt.dev.Compiler.main(Compiler.java:113)
```
RELNOTES=n/a
PiperOrigin-RevId: 711434202
copybara-service bot pushed a commit that referenced this issue Jan 2, 2025
…=21` to set the Java version for tests, and do so in CI. (The property value still _defaults_ to the JDK that you use to run Maven, so passing the flag is not _necessary_.)

This lets us use whatever Java version we want\[1\] for executing Maven itself—and thus for executing any plugins that aren't toolchain-aware. (I even hacked up our toolchain configuration to run tests under Java 24, and it worked.) I've changed our CI to do that, too, by always using Java 23. (This makes the explicit choice of Java 23 for _javac_ redundant under CI, as well as on our Google workstations. However, it can be useful for anyone who builds Guava locally while having an older JDK as the default version.)

Notably, that means that we can use a new version (like Java 23) for running the GWT plugin, which lets us upgrade to GWT 2.12.1 (cl/711417161), which uses an Eclipse compiler with bytecode version 55 (Java 11)\[2\]. (This means that users who build `guava-gwt` locally with Java 8 will need to [upgrade their build JDK to at least Java 11](https://github.com/google/guava/issues/6549)—or skip building `guava-gwt` if they don't need it.)

That GWT upgrade is in turn necessary in order for us to be able to use use [JSpecify annotations](jspecify/jspecify#239) from our GWT artifact.

In theory, this could also prepare us for further changes, like more easily running tests under multiple versions during our release process (in addition to how we already do so for CI), though there are already other ways of doing that by hacking up our release script or `pom.xml`. And I'm not sure that I'd really want to do that, anyway. (See also some notes that I've added to cl/639128020.)

I also did some related cleanup:

- Our `--no-module-directories` configuration probably became Just Wrong back in cl/655647768: It should be based on the version that we use to build Javadoc (which is currently always 11), not the version that Maven is running under. It probably mostly doesn't matter because we probably mostly don't try to run Javadoc under other versions, but I'd like to be able to do so, so this is a step forward.
- `-Djava.security.manager=allow` is not necessary now that we've cleaned up our usages of `SecurityManager`. (And that's fortunate, as it seems difficult to [active a profile based on a range of values of an arbitrary "my test JRE version" property](https://issues.apache.org/jira/browse/MNG-3328), as opposed to activate it based on the JDK that Maven is running under.)

I expect that this CL is going to fail Gradle integration testing because that testing (when last I checked) required Java 11. I'll try to figure that out once I see the full CI results, which may well reveal bigger problems.

Fixes #7492 (by making `setup-java` download all the toolchains that we need)

\[1\] I mean, I suspect that Maven support lags new JDKs somewhat, and I've seen problems with other versions (as documented in cl/488902996). But at least we don't have to use the same Java version for executing Maven itself as we do for executing tests.

\[2\] That was causing this error:

```
[INFO] --- gwt:2.10.0:compile (gwt-compile) @ guava-gwt ---
Error: [ERROR] Unexpected internal compiler error
[INFO] java.lang.UnsupportedClassVersionError: org/eclipse/jdt/internal/compiler/classfmt/ClassFormatException has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
[INFO] 	at java.lang.ClassLoader.defineClass1(Native Method)
[INFO] 	at java.lang.ClassLoader.defineClass(ClassLoader.java:757)
[INFO] 	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
[INFO] 	at java.net.URLClassLoader.defineClass(URLClassLoader.java:473)
[INFO] 	at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
[INFO] 	at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
[INFO] 	at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
[INFO] 	at java.security.AccessController.doPrivileged(Native Method)
[INFO] 	at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
[INFO] 	at java.lang.ClassLoader.loadClass(ClassLoader.java:419)
[INFO] 	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
[INFO] 	at java.lang.ClassLoader.loadClass(ClassLoader.java:352)
[INFO] 	at com.google.gwt.dev.javac.CompilationStateBuilder.doBuildFrom(CompilationStateBuilder.java:488)
[INFO] 	at com.google.gwt.dev.javac.CompilationStateBuilder.buildFrom(CompilationStateBuilder.java:464)
[INFO] 	at com.google.gwt.dev.cfg.ModuleDef.getCompilationState(ModuleDef.java:426)
[INFO] 	at com.google.gwt.dev.Precompile.validate(Precompile.java:145)
[INFO] 	at com.google.gwt.dev.Compiler.compile(Compiler.java:184)
[INFO] 	at com.google.gwt.dev.Compiler.compile(Compiler.java:143)
[INFO] 	at com.google.gwt.dev.Compiler.compile(Compiler.java:132)
[INFO] 	at com.google.gwt.dev.Compiler$1.run(Compiler.java:110)
[INFO] 	at com.google.gwt.dev.CompileTaskRunner.doRun(CompileTaskRunner.java:55)
[INFO] 	at com.google.gwt.dev.CompileTaskRunner.runWithAppropriateLogger(CompileTaskRunner.java:50)
[INFO] 	at com.google.gwt.dev.Compiler.main(Compiler.java:113)
```
RELNOTES=n/a
PiperOrigin-RevId: 711434202
copybara-service bot pushed a commit that referenced this issue Jan 2, 2025
…=21` to set the Java version for tests, and do so in CI. (The property value still _defaults_ to the JDK that you use to run Maven, so passing the flag is not _necessary_.)

This lets us use whatever Java version we want\[1\] for executing Maven itself—and thus for executing any plugins that aren't toolchain-aware. (I even hacked up our toolchain configuration to run tests under Java 24, and it worked.) I've changed our CI to do that, too, by always using Java 23. (This makes the explicit choice of Java 23 for _javac_ redundant under CI, as well as on our Google workstations. However, it can be useful for anyone who builds Guava locally while having an older JDK as the default version.)

Notably, that means that we can use a new version (like Java 23) for running the GWT plugin, which lets us upgrade to GWT 2.12.1 (cl/711417161), which uses an Eclipse compiler with bytecode version 55 (Java 11)\[2\]. (This means that users who build `guava-gwt` locally with Java 8 will need to [upgrade their build JDK to at least Java 11](https://github.com/google/guava/issues/6549)—or skip building `guava-gwt` if they don't need it.)

That GWT upgrade is in turn necessary in order for us to be able to use use [JSpecify annotations](jspecify/jspecify#239) from our GWT artifact.

In theory, this could also prepare us for further changes, like more easily running tests under multiple versions during our release process (in addition to how we already do so for CI), though there are already other ways of doing that by hacking up our release script or `pom.xml`. And I'm not sure that I'd really want to do that, anyway. (See also some notes that I've added to cl/639128020.)

I also did some related cleanup:

- Our `--no-module-directories` configuration probably became Just Wrong back in cl/655647768: It should be based on the version that we use to build Javadoc (which is currently always 11), not the version that Maven is running under. It probably mostly doesn't matter because we probably mostly don't try to run Javadoc under other versions, but I'd like to be able to do so, so this is a step forward.
- `-Djava.security.manager=allow` is not necessary now that we've cleaned up our usages of `SecurityManager`. (And that's fortunate, as it seems difficult to [active a profile based on a range of values of an arbitrary "my test JRE version" property](https://issues.apache.org/jira/browse/MNG-3328), as opposed to activate it based on the JDK that Maven is running under.)

Fixes #7492 (by making `setup-java` download all the toolchains that we need)

\[1\] I mean, I suspect that Maven support lags new JDKs somewhat, and I've seen problems with other versions (as documented in cl/488902996). But at least we don't have to use the same Java version for executing Maven itself as we do for executing tests.

\[2\] That was causing this error:

```
[INFO] --- gwt:2.10.0:compile (gwt-compile) @ guava-gwt ---
Error: [ERROR] Unexpected internal compiler error
[INFO] java.lang.UnsupportedClassVersionError: org/eclipse/jdt/internal/compiler/classfmt/ClassFormatException has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
[INFO] 	at java.lang.ClassLoader.defineClass1(Native Method)
[INFO] 	at java.lang.ClassLoader.defineClass(ClassLoader.java:757)
[INFO] 	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
[INFO] 	at java.net.URLClassLoader.defineClass(URLClassLoader.java:473)
[INFO] 	at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
[INFO] 	at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
[INFO] 	at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
[INFO] 	at java.security.AccessController.doPrivileged(Native Method)
[INFO] 	at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
[INFO] 	at java.lang.ClassLoader.loadClass(ClassLoader.java:419)
[INFO] 	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
[INFO] 	at java.lang.ClassLoader.loadClass(ClassLoader.java:352)
[INFO] 	at com.google.gwt.dev.javac.CompilationStateBuilder.doBuildFrom(CompilationStateBuilder.java:488)
[INFO] 	at com.google.gwt.dev.javac.CompilationStateBuilder.buildFrom(CompilationStateBuilder.java:464)
[INFO] 	at com.google.gwt.dev.cfg.ModuleDef.getCompilationState(ModuleDef.java:426)
[INFO] 	at com.google.gwt.dev.Precompile.validate(Precompile.java:145)
[INFO] 	at com.google.gwt.dev.Compiler.compile(Compiler.java:184)
[INFO] 	at com.google.gwt.dev.Compiler.compile(Compiler.java:143)
[INFO] 	at com.google.gwt.dev.Compiler.compile(Compiler.java:132)
[INFO] 	at com.google.gwt.dev.Compiler$1.run(Compiler.java:110)
[INFO] 	at com.google.gwt.dev.CompileTaskRunner.doRun(CompileTaskRunner.java:55)
[INFO] 	at com.google.gwt.dev.CompileTaskRunner.runWithAppropriateLogger(CompileTaskRunner.java:50)
[INFO] 	at com.google.gwt.dev.Compiler.main(Compiler.java:113)
```
RELNOTES=n/a
PiperOrigin-RevId: 711434202
@cpovirk
Copy link
Member Author

cpovirk commented Jan 2, 2025

setup-java should now be downloading everything that the build needs.

It is possible that we'd accidentally regress that in the future. Probably what we should do is disable toolchains-maven-plugin during CI runs. But I haven't tried yet.

copybara-service bot pushed a commit that referenced this issue Jan 2, 2025
- Use Temurin over Zulu. Per [advice](#7492 (comment)) from @ben-manes, LTS versions of Temurin [come pre-installed](https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#Hosted-Tool-Cache).
- But be willing to run with any JDK of the appropriate version that's available, rather than requiring Zulu. (Not that this makes a huge difference, given that we'll still *download* Temurin JDKs. I didn't think this through much.)
- Make the test jobs fail [if they need to download a needed JDK](https://github.com/linux-china/toolchains-maven-plugin#how-to-skip-toolchains-maven-plugin-on-cicd-platform) because we didn't already put that one in place with `setup-java`. (Our other CI jobs, which publish snapshots to Sonatype and regenerate snapshot Javadoc, will continue to tolerate missing JDKs. We could change them, too, by making their scripts pass through options to identify the run as a CI run.) This should help us keep our versions in sync, and it should prevent us from silently falling back to slower downloads, per b/334979149.
- Use Java 21 to generate Javadoc (as that's the best we can do now without [further trouble](#6790 (comment))). I've made sure to make it available through `setup-java`, including for generating Sonatype snapshots, which [do include Javadoc](https://oss.sonatype.org/content/repositories/snapshots/com/google/guava/guava/HEAD-jre-SNAPSHOT/). Plus, use Java 23 for the Maven VM itself there (so as to standardize on the same version as we already use for the Maven VM itself during our test workflows as of cl/711476575).
- Fix a few Javadoc warnings, leaving behind only [a handful that we can't easily do anything about](#6790 (comment)).
- Download Java 11 only when it is required. Currently, that's for JDiff and for our Gradle integration tests.

There is a decent change that this CL will break something, possibly not until we run the snapshot steps after submission... :)

RELNOTES=n/a
PiperOrigin-RevId: 711520051
copybara-service bot pushed a commit that referenced this issue Jan 3, 2025
- Use Temurin over Zulu. Per [advice](#7492 (comment)) from @ben-manes, LTS versions of Temurin [come pre-installed](https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#Hosted-Tool-Cache).
- But be willing to run with any JDK of the appropriate version that's available, rather than requiring Zulu. (Not that this makes a huge difference, given that we'll still *download* Temurin JDKs. I didn't think this through much. I guess you can now at least avoiding downloading a Temurin JDK if you make sure you already have enough JDKs registered and you pass `-Dtoolchain.skip`.)
- Make the test jobs fail [if they need to download a needed JDK](https://github.com/linux-china/toolchains-maven-plugin#how-to-skip-toolchains-maven-plugin-on-cicd-platform) because we didn't already put that one in place with `setup-java`. (Our other CI jobs, which publish snapshots to Sonatype and regenerate snapshot Javadoc, will continue to tolerate missing JDKs. We could change them, too, by making their scripts pass through options to identify the run as a CI run.) This should help us keep our versions in sync, and it should prevent us from silently falling back to slower downloads, per b/334979149.
- Use Java 21 to generate Javadoc (as that's the best we can do now without [further trouble](#6790 (comment))). I've made sure to make Java 21 available through `setup-java`, including for generating Sonatype snapshots, which [do include Javadoc](https://oss.sonatype.org/content/repositories/snapshots/com/google/guava/guava/HEAD-jre-SNAPSHOT/). Plus, use Java 23 for the Maven VM itself there (so as to standardize on the same version as we already use for the Maven VM itself during our test workflows as of cl/711476575).
- Fix a few Javadoc warnings, leaving behind only [a handful that we can't easily do anything about](#6790 (comment)).
- Download Java 11 only when it is required. Currently, that's for JDiff and for our Gradle integration tests.

There is a decent chance that this CL will break something, possibly not until we run the snapshot steps after submission... :)

RELNOTES=n/a
PiperOrigin-RevId: 711746683
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment