error-prone
error-prone copied to clipboard
Consider using Multi-Release jars for Error Prone
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!)
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-javaregisters toolchains but doesn't download EAs from https://jdk.java.net/24/,oracle-actions/setup-javadoes 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
- I just recently set up Guava to automatically download [edit: and register] toolchains during the build with
toolchains-maven-plugin(not to be confused withmaven-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
--systemwith<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 :)
linux-china/toolchains-maven-plugindoesn'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-pluginabout built-in support for--system: https://issues.apache.org/jira/browse/MCOMPILER-596
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.