error-prone icon indicating copy to clipboard operation
error-prone copied to clipboard

Consider using Multi-Release jars for Error Prone

Open cushon opened this issue 2 years ago • 4 comments

This bug tracks trying to use Multi-Release jar files for Error Prone.

The main use-case is that some checks need to handle AST nodes that not available in all supported JDK versions. Currently we're mostly using reflection to work around that, with mrjars we could move some of that logic behind an internal API and provide implementations that used the new AST nodes for JDK versions that supported them, avoiding the reflection. (e.g. #3737, https://github.com/google/error-prone/pull/3610#discussion_r1051486417)

One of the barriers to doing this is figuring out the best way to produce mrjars with maven. (If anyone reading this has relevant experience, suggestions are welcome!)

cushon avatar Feb 04 '23 20:02 cushon

Some WIP on this in https://github.com/google/error-prone/pull/4521

  • maven's <multiReleaseOutput> assumes --release, which javac doesn't allow combing with --add-exports=. Maven doesn't appear to support --system. So the only option for compiling version-specific code seems to be running on the corresponding JDK's javac, which can be done with <jdkToolchain><version>...</version></jdkToolchain> and <fork>
  • this requires having a maven toolchain registered for JDK EAs. actions/setup-java registers toolchains but doesn't download EAs from https://jdk.java.net/24/, oracle-actions/setup-java does the latter but not the former. There are some breadcrumbs here that might work: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#modifying-the-toolchain-vendor-for-jdks

cushon avatar Aug 05 '24 15:08 cushon

  • I just recently set up Guava to automatically download [edit: and register] toolchains during the build with toolchains-maven-plugin (not to be confused with maven-toolchains-plugin, which we also now use). I didn't test downloading an EA JDK, but I see versions like "24-ea+7" in this list linked from the plugin's GitHub page, so I would expect it to work. I do suspect that that is slower (maybe ~30 seconds in the case of Guava, for which we're downloading 1-2 toolchains during the build), but I saw varied enough numbers (discussed in internal issue 334979149) that I didn't draw firm conclusions.
  • I had figured that we could arrange for --system with <compilerArgs>, but I didn't test, and of course that doesn't save us from having to download the JDK whose system we want. Then we'd have to figure out how to get access to the path we need. I speculated on a Rube Goldberg setup for that in https://github.com/google/guava/issues/3990#issuecomment-2256002204, but, uh, you first :)

cpovirk avatar Aug 05 '24 15:08 cpovirk

  • linux-china/toolchains-maven-plugin doesn't seem to support EAs, I filed https://github.com/linux-china/toolchains-maven-plugin/issues/13
  • I also filed a FR against maven-toolchain-plugin about built-in support for --system: https://issues.apache.org/jira/browse/MCOMPILER-596

cushon avatar Aug 07 '24 23:08 cushon

I updated #4586 with a multi-release JAR setup that seems to work, at least locally. TBD what aspect (if any) of the GitHub Actions configuration has to be adjusted.

Stephan202 avatar Dec 28 '24 22:12 Stephan202