Skip to content

Commit a5efa33

Browse files
sgammonError Prone Team
authored and
Error Prone Team
committed
feat: add jpms definition for annotations
## Summary Minimal set of changes to ship a `module-info.java`, and support JVM 1.8 for the `annotations` module only. ### Reasoning It costs almost nothing to support _only_ the annotations on JVM 1.8, for projects which transitively include `error-prone-annotations`, which can happen via a simple dependency on something like Guava. But, it would be ideal to [ship a `module-info.java`](#2649), so `annotations` is now a `Multi-Release` JAR, with a `module-info.class` in `META-INF/versions/9`. I am working downstream to [support JPMS in Guava](google/guava#2970), and this PR will be necessary for that to eventually land (without hackery). [Checker Framework recently merged their support](typetools/checker-framework#6326) which means Error Prone is one of the last things on the classpath for Guava without a `module-info.java` definition. Automatic Modules also aren't the answer because they cannot be used with `jlink`. Such dependencies must be processed by tools like Moditect before they can be used in fully modular Java builds. Because Error Prone Annotations is a dependency in Guava, and is itself very popular, many projects need Error Prone to adopt JPMS so they can ship their own code with modular Java support. There may be libraries out there that depend on the annotations _and not the compiler_, who wish to ship a MRJAR and retain JVM 1.8 support (Guava). ### Non-release version number change One wrinkle here is that the Maven project version [is used unconditionally](https://github.com/apache/maven-compiler-plugin/blob/74cfc72acae4f55708bca189b2170167e83df6b3/src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java#L304-L305) [as the `--module-version`][0]; however, [`HEAD-SNAPSHOT` is not a valid module identifier](https://lists.apache.org/thread/qtghq13qgjoc4pn6ovsdxgnjnm4ozv4d). This leaves only a few choices to support JPMS through recent (`3.8.x+`) Maven Compiler plugin versions: - `HEAD-SNAPSHOT` needs to become `1.0-HEAD-SNAPSHOT`, and then it is a valid `--module-version` - Or, Maven Compiler Plugin needs to ship a bugfix and Error Prone will need to wait for a release (if a bugfix ships at all) I understand this can be a breaking change somewhere within Google, but I don't see a way around this without resorting to severe build hacks. I've gotten it to build anyway by building the `module-info.java` only in a separate Maven project, and then copying it into the JAR at the last moment, but there are serious issues with that route so I suggest it be abandoned in favor of a version string change during dev, if possible. ## Changelog - feat: add `module-info` to `annotations` module - feat: ship `annotations` as a `Multi-Release` JAR - feat: support `1.8` through latest JDK for `annotations` module - fix: remove automatic module definition from `annotations` module - fix: `HEAD-SNAPSHOT` → `1.0-HEAD-SNAPSHOT`, because of a Maven Compiler Plugin issue [precluding use as a module version][0] Fixes and closes #2649 [0]: https://issues.apache.org/jira/browse/MCOMPILER-579 Fixes #4311 FUTURE_COPYBARA_INTEGRATE_REVIEW=#4311 from sgammon:feat/jpms d209b0c PiperOrigin-RevId: 614005681
1 parent 9da2d55 commit a5efa33

File tree

11 files changed

+75
-12
lines changed

11 files changed

+75
-12
lines changed

annotation/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<parent>
2222
<groupId>com.google.errorprone</groupId>
2323
<artifactId>error_prone_parent</artifactId>
24-
<version>HEAD-SNAPSHOT</version>
24+
<version>1.0-HEAD-SNAPSHOT</version>
2525
</parent>
2626

2727
<name>@BugPattern annotation</name>

annotations/pom.xml

+33-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<parent>
2222
<groupId>com.google.errorprone</groupId>
2323
<artifactId>error_prone_parent</artifactId>
24-
<version>HEAD-SNAPSHOT</version>
24+
<version>1.0-HEAD-SNAPSHOT</version>
2525
</parent>
2626

2727
<name>error-prone annotations</name>
@@ -49,10 +49,40 @@
4949
<groupId>org.apache.maven.plugins</groupId>
5050
<artifactId>maven-compiler-plugin</artifactId>
5151
<configuration>
52-
<source>8</source>
53-
<target>8</target>
5452
<compilerArgs combine.self="override" />
5553
</configuration>
54+
<executions>
55+
<execution>
56+
<id>default-compile</id>
57+
<configuration>
58+
<source>1.8</source>
59+
<target>1.8</target>
60+
<excludes>
61+
<exclude>module-info.java</exclude>
62+
</excludes>
63+
</configuration>
64+
</execution>
65+
<execution>
66+
<id>compile-java9</id>
67+
<configuration>
68+
<source>9</source>
69+
<target>9</target>
70+
<release>9</release>
71+
<multiReleaseOutput>true</multiReleaseOutput>
72+
</configuration>
73+
</execution>
74+
</executions>
75+
</plugin>
76+
<plugin>
77+
<groupId>org.apache.maven.plugins</groupId>
78+
<artifactId>maven-jar-plugin</artifactId>
79+
<configuration>
80+
<archive>
81+
<manifestEntries>
82+
<Multi-Release>true</Multi-Release>
83+
</manifestEntries>
84+
</archive>
85+
</configuration>
5686
</plugin>
5787
</plugins>
5888
</build>
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2015 The Error Prone Authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
open module com.google.errorprone.annotation {
18+
requires java.base;
19+
requires java.compiler;
20+
21+
exports com.google.errorprone.annotations;
22+
exports com.google.errorprone.annotations.concurrent;
23+
}

check_api/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<parent>
2222
<groupId>com.google.errorprone</groupId>
2323
<artifactId>error_prone_parent</artifactId>
24-
<version>HEAD-SNAPSHOT</version>
24+
<version>1.0-HEAD-SNAPSHOT</version>
2525
</parent>
2626

2727
<name>error-prone check api</name>

core/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<parent>
2222
<groupId>com.google.errorprone</groupId>
2323
<artifactId>error_prone_parent</artifactId>
24-
<version>HEAD-SNAPSHOT</version>
24+
<version>1.0-HEAD-SNAPSHOT</version>
2525
</parent>
2626

2727
<name>error-prone library</name>

docgen/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<parent>
2222
<groupId>com.google.errorprone</groupId>
2323
<artifactId>error_prone_parent</artifactId>
24-
<version>HEAD-SNAPSHOT</version>
24+
<version>1.0-HEAD-SNAPSHOT</version>
2525
</parent>
2626

2727
<name>Documentation tool for generating Error Prone bugpattern documentation</name>

docgen_processor/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<parent>
2222
<groupId>com.google.errorprone</groupId>
2323
<artifactId>error_prone_parent</artifactId>
24-
<version>HEAD-SNAPSHOT</version>
24+
<version>1.0-HEAD-SNAPSHOT</version>
2525
</parent>
2626

2727
<name>JSR-269 annotation processor for @BugPattern annotation</name>

pom.xml

+11-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<name>Error Prone parent POM</name>
2222
<groupId>com.google.errorprone</groupId>
2323
<artifactId>error_prone_parent</artifactId>
24-
<version>HEAD-SNAPSHOT</version>
24+
<version>1.0-HEAD-SNAPSHOT</version>
2525
<packaging>pom</packaging>
2626

2727
<description>Error Prone is a static analysis tool for Java that catches common programming mistakes at compile-time.</description>
@@ -204,6 +204,16 @@
204204
<exclude>**/testdata/**</exclude>
205205
</testExcludes>
206206
</configuration>
207+
<executions>
208+
<execution>
209+
<id>default-compile</id>
210+
<configuration>
211+
<compilerArgs combine.children="append">
212+
<arg>-Xlint:-options</arg>
213+
</compilerArgs>
214+
</configuration>
215+
</execution>
216+
</executions>
207217
</plugin>
208218
<plugin>
209219
<groupId>org.apache.maven.plugins</groupId>

refaster/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<parent>
2020
<artifactId>error_prone_parent</artifactId>
2121
<groupId>com.google.errorprone</groupId>
22-
<version>HEAD-SNAPSHOT</version>
22+
<version>1.0-HEAD-SNAPSHOT</version>
2323
</parent>
2424
<modelVersion>4.0.0</modelVersion>
2525

test_helpers/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<parent>
2222
<groupId>com.google.errorprone</groupId>
2323
<artifactId>error_prone_parent</artifactId>
24-
<version>HEAD-SNAPSHOT</version>
24+
<version>1.0-HEAD-SNAPSHOT</version>
2525
</parent>
2626

2727
<name>error-prone test helpers</name>

type_annotations/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<parent>
2222
<groupId>com.google.errorprone</groupId>
2323
<artifactId>error_prone_parent</artifactId>
24-
<version>HEAD-SNAPSHOT</version>
24+
<version>1.0-HEAD-SNAPSHOT</version>
2525
</parent>
2626

2727
<name>error-prone type annotations</name>

0 commit comments

Comments
 (0)