Skip to content

Commit cf0d53a

Browse files
gaulclaude
andcommitted
Run Error Prone only where javac can load it
CodeQL reads the POM, sees that the artifact targets Java 17, and builds with JDK 17, where javac cannot load Error Prone's Java 21 class files. It also passes -Denforcer.skip, so requiring JDK 21 does not redirect it to a newer one; compiling has to work on the version the artifact targets. Move Error Prone into a profile that activates on JDK 21 and newer. A full build still wants that JDK, since Checkstyle ships Java 21 class files too, and the enforcer says so rather than letting either fail with an UnsupportedClassVersionError stack trace. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01M5JVWJN7L3NWmcsYvjeCfc
1 parent abf652c commit cf0d53a

1 file changed

Lines changed: 49 additions & 26 deletions

File tree

‎pom.xml‎

Lines changed: 49 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,51 @@
4646
</distributionManagement>
4747

4848
<profiles>
49+
<profile>
50+
<!-- Error Prone ships Java 21 class files, so javac can only load it on
51+
a JDK that new. Keep the build working on ${java.version}, which is
52+
what the artifact targets and what tools such as CodeQL autobuild
53+
select, and run Error Prone wherever it can run. -->
54+
<id>errorprone</id>
55+
<activation>
56+
<jdk>[21,)</jdk>
57+
</activation>
58+
<build>
59+
<plugins>
60+
<plugin>
61+
<groupId>org.apache.maven.plugins</groupId>
62+
<artifactId>maven-compiler-plugin</artifactId>
63+
<configuration>
64+
<fork>true</fork>
65+
<compilerArgs combine.children="append">
66+
<arg>-XDcompilePolicy=simple</arg>
67+
<arg>-XDaddTypeAnnotationsToSymbol=true</arg>
68+
<arg>--should-stop=ifError=FLOW</arg>
69+
<arg>-Xplugin:ErrorProne</arg>
70+
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED</arg>
71+
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED</arg>
72+
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED</arg>
73+
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED</arg>
74+
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED</arg>
75+
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED</arg>
76+
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED</arg>
77+
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED</arg>
78+
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED</arg>
79+
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED</arg>
80+
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED</arg>
81+
</compilerArgs>
82+
<annotationProcessorPaths>
83+
<path>
84+
<groupId>com.google.errorprone</groupId>
85+
<artifactId>error_prone_core</artifactId>
86+
<version>2.50.0</version>
87+
</path>
88+
</annotationProcessorPaths>
89+
</configuration>
90+
</plugin>
91+
</plugins>
92+
</build>
93+
</profile>
4994
<profile>
5095
<id>release</id>
5196
<build>
@@ -118,32 +163,9 @@
118163
<release>${java.version}</release>
119164
<showDeprecation>true</showDeprecation>
120165
<showWarnings>true</showWarnings>
121-
<fork>true</fork>
122166
<compilerArgs>
123167
<arg>-Xlint:all</arg>
124-
<arg>-XDcompilePolicy=simple</arg>
125-
<arg>-XDaddTypeAnnotationsToSymbol=true</arg>
126-
<arg>--should-stop=ifError=FLOW</arg>
127-
<arg>-Xplugin:ErrorProne</arg>
128-
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED</arg>
129-
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED</arg>
130-
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED</arg>
131-
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED</arg>
132-
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED</arg>
133-
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED</arg>
134-
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED</arg>
135-
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED</arg>
136-
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED</arg>
137-
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED</arg>
138-
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED</arg>
139168
</compilerArgs>
140-
<annotationProcessorPaths>
141-
<path>
142-
<groupId>com.google.errorprone</groupId>
143-
<artifactId>error_prone_core</artifactId>
144-
<version>2.50.0</version>
145-
</path>
146-
</annotationProcessorPaths>
147169
</configuration>
148170
</plugin>
149171
<plugin>
@@ -277,9 +299,10 @@
277299
<requireMavenVersion>
278300
<version>3.0.5</version>
279301
</requireMavenVersion>
280-
<!-- Error Prone ships Java 21 class files, so javac cannot
281-
load it on an older JDK. The artifact itself still
282-
targets ${java.version}, via release. -->
302+
<!-- Checkstyle and Error Prone both ship Java 21 class
303+
files, so a full build needs a JDK that new. Compiling
304+
alone still works on ${java.version}, which is what the
305+
artifact targets, for tools that skip the enforcer. -->
283306
<requireJavaVersion>
284307
<version>[21,)</version>
285308
</requireJavaVersion>

0 commit comments

Comments
 (0)