From 0e9536471b6b8e7e03d29584eceb8a0e0f3240d7 Mon Sep 17 00:00:00 2001 From: Sam Gammon Date: Fri, 8 Mar 2024 13:18:34 -0800 Subject: [PATCH] feat: add jpms definition for `annotations` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 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](https://github.com/google/guava/issues/2970), and this PR will be necessary for that to eventually land (without hackery). [Checker Framework recently merged their support](https://github.com/typetools/checker-framework/pull/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 COPYBARA_INTEGRATE_REVIEW=https://github.com/google/error-prone/pull/4311 from sgammon:feat/jpms d209b0c19a568b5385b968da17f2cd5ef670331a PiperOrigin-RevId: 614026439 --- annotation/pom.xml | 2 +- annotations/pom.xml | 36 ++++++++++++++++++++-- annotations/src/main/java/module-info.java | 23 ++++++++++++++ check_api/pom.xml | 2 +- core/pom.xml | 2 +- docgen/pom.xml | 2 +- docgen_processor/pom.xml | 2 +- pom.xml | 12 +++++++- refaster/pom.xml | 2 +- test_helpers/pom.xml | 2 +- type_annotations/pom.xml | 2 +- 11 files changed, 75 insertions(+), 12 deletions(-) create mode 100644 annotations/src/main/java/module-info.java diff --git a/annotation/pom.xml b/annotation/pom.xml index 59f69a89d89..fbbba7c5524 100644 --- a/annotation/pom.xml +++ b/annotation/pom.xml @@ -21,7 +21,7 @@ com.google.errorprone error_prone_parent - HEAD-SNAPSHOT + 1.0-HEAD-SNAPSHOT @BugPattern annotation diff --git a/annotations/pom.xml b/annotations/pom.xml index 03c522c0391..39a06275850 100644 --- a/annotations/pom.xml +++ b/annotations/pom.xml @@ -21,7 +21,7 @@ com.google.errorprone error_prone_parent - HEAD-SNAPSHOT + 1.0-HEAD-SNAPSHOT error-prone annotations @@ -49,10 +49,40 @@ org.apache.maven.plugins maven-compiler-plugin - 8 - 8 + + + default-compile + + 1.8 + 1.8 + + module-info.java + + + + + compile-java9 + + 9 + 9 + 9 + true + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + true + + + diff --git a/annotations/src/main/java/module-info.java b/annotations/src/main/java/module-info.java new file mode 100644 index 00000000000..779f8fe61eb --- /dev/null +++ b/annotations/src/main/java/module-info.java @@ -0,0 +1,23 @@ +/* + * Copyright 2015 The Error Prone Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +open module com.google.errorprone.annotation { + requires java.base; + requires java.compiler; + + exports com.google.errorprone.annotations; + exports com.google.errorprone.annotations.concurrent; +} diff --git a/check_api/pom.xml b/check_api/pom.xml index 397c42e88c6..1a96ffd6473 100644 --- a/check_api/pom.xml +++ b/check_api/pom.xml @@ -21,7 +21,7 @@ com.google.errorprone error_prone_parent - HEAD-SNAPSHOT + 1.0-HEAD-SNAPSHOT error-prone check api diff --git a/core/pom.xml b/core/pom.xml index 68eae1cd680..1eb5aec8f77 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -21,7 +21,7 @@ com.google.errorprone error_prone_parent - HEAD-SNAPSHOT + 1.0-HEAD-SNAPSHOT error-prone library diff --git a/docgen/pom.xml b/docgen/pom.xml index 784673a1d5d..8ee00587502 100644 --- a/docgen/pom.xml +++ b/docgen/pom.xml @@ -21,7 +21,7 @@ com.google.errorprone error_prone_parent - HEAD-SNAPSHOT + 1.0-HEAD-SNAPSHOT Documentation tool for generating Error Prone bugpattern documentation diff --git a/docgen_processor/pom.xml b/docgen_processor/pom.xml index 351787a725f..7d97a4cb4ca 100644 --- a/docgen_processor/pom.xml +++ b/docgen_processor/pom.xml @@ -21,7 +21,7 @@ com.google.errorprone error_prone_parent - HEAD-SNAPSHOT + 1.0-HEAD-SNAPSHOT JSR-269 annotation processor for @BugPattern annotation diff --git a/pom.xml b/pom.xml index 09b4a4b3f88..f7cad3c75bd 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ Error Prone parent POM com.google.errorprone error_prone_parent - HEAD-SNAPSHOT + 1.0-HEAD-SNAPSHOT pom Error Prone is a static analysis tool for Java that catches common programming mistakes at compile-time. @@ -204,6 +204,16 @@ **/testdata/** + + + default-compile + + + -Xlint:-options + + + + org.apache.maven.plugins diff --git a/refaster/pom.xml b/refaster/pom.xml index d7951f0e492..968b0c2bae4 100644 --- a/refaster/pom.xml +++ b/refaster/pom.xml @@ -19,7 +19,7 @@ error_prone_parent com.google.errorprone - HEAD-SNAPSHOT + 1.0-HEAD-SNAPSHOT 4.0.0 diff --git a/test_helpers/pom.xml b/test_helpers/pom.xml index cf4af121a75..76fbfaf30d9 100644 --- a/test_helpers/pom.xml +++ b/test_helpers/pom.xml @@ -21,7 +21,7 @@ com.google.errorprone error_prone_parent - HEAD-SNAPSHOT + 1.0-HEAD-SNAPSHOT error-prone test helpers diff --git a/type_annotations/pom.xml b/type_annotations/pom.xml index b2495a2167f..365123af188 100644 --- a/type_annotations/pom.xml +++ b/type_annotations/pom.xml @@ -21,7 +21,7 @@ com.google.errorprone error_prone_parent - HEAD-SNAPSHOT + 1.0-HEAD-SNAPSHOT error-prone type annotations