Skip to content

Commit

Permalink
feat(jpms): add module-info definition for guava
Browse files Browse the repository at this point in the history
This changeset adds full support for modular Java builds in Guava,
and in libraries which depend on Guava.

The Guava JAR for JRE now structures as a Multi-Release JAR, with
a module definition situated in `META-INF/versions/9/`. Guava
remains compatible with JDK 8.

- feat: add `module-info.java` to `guava` module
- feat(jpms): add `module-info.java` to `failureaccess`
- feat(jpms): add `module-info.java` to `testlib`
- fix: necessary fixes to get testsuite running on modular java
- chore: update `guava` to build MRJAR
- chore: adjust dev version → `1.0-HEAD-[jre|android]-SNAPSHOT`
- chore: upgrade maven compiler plugin → `3.12.1`

Fixes and closes google#2970

Relates-To: elide-dev/jpms#1
Signed-off-by: Sam Gammon <[email protected]>
  • Loading branch information
sgammon committed Feb 8, 2025
1 parent 57ec95c commit bf0885d
Show file tree
Hide file tree
Showing 18 changed files with 310 additions and 58 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ consult the
## Snapshots and Documentation

Snapshots of Guava built from the `master` branch are available through Maven
using version `HEAD-jre-SNAPSHOT`, or `HEAD-android-SNAPSHOT` for the Android
using version `1.0-HEAD-jre-SNAPSHOT`, or `1.0-HEAD-android-SNAPSHOT` for the Android
flavor.

[Snapshot API Javadoc][guava-snapshot-api-docs] as well as
Expand Down Expand Up @@ -108,7 +108,7 @@ flavor.
options open in case of surprises (like, say, a serious security problem).

3. Guava has one dependency that is needed for linkage at runtime:
`com.google.guava:failureaccess:1.0.2`. It also has
`com.google.guava:failureaccess:1.0.3`. It also has
[some annotation-only dependencies][guava-deps], which we discuss in more
detail at that link.

Expand Down
2 changes: 1 addition & 1 deletion android/guava-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<groupId>com.google.guava</groupId>
<artifactId>guava-bom</artifactId>
<version>HEAD-android-SNAPSHOT</version>
<version>1.0-HEAD-android-SNAPSHOT</version>
<packaging>pom</packaging>

<parent>
Expand Down
2 changes: 1 addition & 1 deletion android/guava-testlib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.google.guava</groupId>
<artifactId>guava-parent</artifactId>
<version>HEAD-android-SNAPSHOT</version>
<version>1.0-HEAD-android-SNAPSHOT</version>
</parent>
<artifactId>guava-testlib</artifactId>
<name>Guava Testing Library</name>
Expand Down
2 changes: 1 addition & 1 deletion android/guava-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.google.guava</groupId>
<artifactId>guava-parent</artifactId>
<version>HEAD-android-SNAPSHOT</version>
<version>1.0-HEAD-android-SNAPSHOT</version>
</parent>
<artifactId>guava-tests</artifactId>
<name>Guava Unit Tests</name>
Expand Down
4 changes: 2 additions & 2 deletions android/guava/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.google.guava</groupId>
<artifactId>guava-parent</artifactId>
<version>HEAD-android-SNAPSHOT</version>
<version>1.0-HEAD-android-SNAPSHOT</version>
</parent>
<artifactId>guava</artifactId>
<packaging>bundle</packaging>
Expand All @@ -21,7 +21,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>failureaccess</artifactId>
<version>1.0.2</version>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
Expand Down
22 changes: 19 additions & 3 deletions android/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.google.guava</groupId>
<artifactId>guava-parent</artifactId>
<version>HEAD-android-SNAPSHOT</version>
<version>1.0-HEAD-android-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Guava Maven Parent</name>
<description>Parent for guava artifacts</description>
Expand Down Expand Up @@ -42,9 +42,11 @@
<module.status>integration</module.status>
<variant.jvmEnvironment>android</variant.jvmEnvironment>
<variant.jvmEnvironmentVariantName>android</variant.jvmEnvironmentVariantName>
<otherVariant.version>HEAD-jre-SNAPSHOT</otherVariant.version>
<otherVariant.version>1.0-HEAD-jre-SNAPSHOT</otherVariant.version>
<otherVariant.jvmEnvironment>standard-jvm</otherVariant.jvmEnvironment>
<otherVariant.jvmEnvironmentVariantName>jre</otherVariant.jvmEnvironmentVariantName>
<publishing.repository.snapshots>https://oss.sonatype.org/content/repositories/snapshots/</publishing.repository.snapshots>
<publishing.repository.releases>https://oss.sonatype.org/service/local/staging/deploy/maven2/</publishing.repository.releases>
</properties>
<issueManagement>
<system>GitHub Issues</system>
Expand Down Expand Up @@ -86,6 +88,7 @@
<module>guava-bom</module>
<module>guava-testlib</module>
<module>guava-tests</module>
<module>../futures/failureaccess</module>
</modules>
<build>
<!-- Handle where Guava deviates from Maven defaults -->
Expand Down Expand Up @@ -211,7 +214,20 @@
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<version>3.4.0</version>
<configuration>
<excludes>
<!-- The root module (where applicable) is withheld because it is provided at `META-INF/versions/9/`. -->
<exclude>/module-info.class</exclude>
<!-- Avoid duplicating compiled classes within the `META-INF/versions/9/` root. -->
<exclude>META-INF/versions/9/com/**/*.class</exclude>
</excludes>
<archive>
<manifestEntries>
<Multi-Release>true</Multi-Release>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
Expand Down
45 changes: 40 additions & 5 deletions futures/failureaccess/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
<parent>
<groupId>com.google.guava</groupId>
<artifactId>guava-parent</artifactId>
<version>26.0-android</version>
<version>1.0-HEAD-jre-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>failureaccess</artifactId>
<version>1.0.2</version>
<packaging>bundle</packaging>
<version>1.0.3</version>
<packaging>jar</packaging>
<name>Guava InternalFutureFailureAccess and InternalFutures</name>
<description>
Contains
Expand All @@ -22,14 +23,47 @@
</description>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-compile</id>
<configuration>
<source>1.8</source>
<target>1.8</target>
<excludes>
<exclude>module-info.java</exclude>
</excludes>
<compilerArgs>
<arg>-Xlint:-removal,-options</arg>
</compilerArgs>
</configuration>
</execution>
<execution>
<id>compile-java9</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<release>9</release>
<multiReleaseOutput>true</multiReleaseOutput>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
<manifestEntries>
<Automatic-Module-Name>com.google.common.util.concurrent.internal</Automatic-Module-Name>
<Multi-Release>true</Multi-Release>
</manifestEntries>
</archive>
<excludes>
<exclude>/module-info.class</exclude>
<exclude>META-INF/versions/9/com/google/common/util/concurrent/internal/*.class</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
Expand All @@ -55,7 +89,8 @@
</executions>
<configuration>
<instructions>
<Export-Package>com.google.common.util.concurrent.internal</Export-Package>
<_fixupmessages>^Classes found in the wrong directory: .*</_fixupmessages>
<Export-Package>com.google.common.util.concurrent.internal,!META-INF.*</Export-Package>
<Bundle-DocURL>https://github.com/google/guava/</Bundle-DocURL>
</instructions>
</configuration>
Expand Down
20 changes: 20 additions & 0 deletions futures/failureaccess/src/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (C) 2024 The Guava 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.
*/

/**
* Guava: Future Internals.
*/
module com.google.common.util.concurrent.internal {
exports com.google.common.util.concurrent.internal;
}
2 changes: 1 addition & 1 deletion guava-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<groupId>com.google.guava</groupId>
<artifactId>guava-bom</artifactId>
<version>HEAD-jre-SNAPSHOT</version>
<version>1.0-HEAD-jre-SNAPSHOT</version>
<packaging>pom</packaging>

<parent>
Expand Down
29 changes: 17 additions & 12 deletions guava-gwt/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.google.guava</groupId>
<artifactId>guava-parent</artifactId>
<version>HEAD-jre-SNAPSHOT</version>
<version>1.0-HEAD-jre-SNAPSHOT</version>
</parent>
<artifactId>guava-gwt</artifactId>
<name>Guava GWT compatible libs</name>
Expand Down Expand Up @@ -45,7 +45,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>failureaccess</artifactId>
<version>1.0.2</version>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
Expand Down Expand Up @@ -134,15 +134,20 @@
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<excludes>
<!-- Yes, we want to exclude ForceGuavaCompilation 4 times: -->
<!-- (And we might as well exclude DummyJavadocClass 3 times (though it would be harmless to include).) -->
<!-- 1. Don't compile it (since that requires a *non-test* dep on gwt-user. -->
<exclude>**/ForceGuavaCompilation*</exclude>
<exclude>**/DummyJavadocClass*</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>default-compile</id>
<configuration>
<excludes>
<!-- Yes, we want to exclude ForceGuavaCompilation 4 times: -->
<!-- (And we might as well exclude DummyJavadocClass 3 times (though it would be harmless to include).) -->
<!-- 1. Don't compile it (since that requires a *non-test* dep on gwt-user. -->
<exclude>**/ForceGuavaCompilation*</exclude>
<exclude>**/DummyJavadocClass*</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
Expand Down Expand Up @@ -262,7 +267,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>failureaccess</artifactId>
<version>1.0.2</version>
<version>1.0.3</version>
<classifier>sources</classifier>
</dependency>
<dependency>
Expand Down
41 changes: 40 additions & 1 deletion guava-testlib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.google.guava</groupId>
<artifactId>guava-parent</artifactId>
<version>HEAD-jre-SNAPSHOT</version>
<version>1.0-HEAD-jre-SNAPSHOT</version>
</parent>
<artifactId>guava-testlib</artifactId>
<name>Guava Testing Library</name>
Expand Down Expand Up @@ -71,6 +71,45 @@
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-compile</id>
<configuration>
<compilerArgs combine.children="append" combine.self="append">
<arg>-XDignore.symbol.file</arg>
</compilerArgs>
</configuration>
</execution>
<execution>
<id>compile-java9</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<release>9</release>
<compileSourceRoots>
<compileSourceRoot>${project.basedir}/src</compileSourceRoot>
</compileSourceRoots>

<!--
JPMS needs access to the module sources to complete a modular Java build. We also need to override
the base compiler settings (in the root `pom.xml`) to enable MRJAR output.
-->
<compilerArgs combine.self="override" combine.children="append">
<arg>-sourcepath</arg>
<arg>${project.basedir}/src</arg>
<arg>--add-reads=com.google.common=ALL-UNNAMED</arg>
<arg>--add-reads=com.google.common.testlib=ALL-UNNAMED</arg>
<!-- https://errorprone.info/docs/installation#maven -->
<arg>-XDcompilePolicy=simple</arg>
<arg>-Xlint:-removal</arg>
<arg>-Xlint:-options</arg>
</compilerArgs>
<multiReleaseOutput>true</multiReleaseOutput>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
Expand Down
30 changes: 30 additions & 0 deletions guava-testlib/src/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (C) 2024 The Guava 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.
*/

/**
* Guava Testlib
*/
open module com.google.common.testlib {
requires java.logging;
requires com.google.common;
requires com.google.common.util.concurrent.internal;

exports com.google.common.collect.testing;
exports com.google.common.collect.testing.features;
exports com.google.common.collect.testing.google;
exports com.google.common.collect.testing.testers;
exports com.google.common.escape.testing;
exports com.google.common.testing;
exports com.google.common.util.concurrent.testing;
}
2 changes: 1 addition & 1 deletion guava-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.google.guava</groupId>
<artifactId>guava-parent</artifactId>
<version>HEAD-jre-SNAPSHOT</version>
<version>1.0-HEAD-jre-SNAPSHOT</version>
</parent>
<artifactId>guava-tests</artifactId>
<name>Guava Unit Tests</name>
Expand Down
Loading

0 comments on commit bf0885d

Please sign in to comment.