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 12, 2025
1 parent d650068 commit 24080f8
Show file tree
Hide file tree
Showing 13 changed files with 259 additions and 35 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Android 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/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion android/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,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 +212,7 @@
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<version>3.4.0</version>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
Expand Down
32 changes: 27 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,34 @@
</description>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<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 +76,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;
}
9 changes: 7 additions & 2 deletions guava-gwt/pom.xml
Original file line number Diff line number Diff line change
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,6 +134,9 @@
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-compile</id>
<configuration>
<excludes>
<!-- Yes, we want to exclude ForceGuavaCompilation 4 times: -->
Expand All @@ -143,6 +146,8 @@
<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
39 changes: 39 additions & 0 deletions guava-testlib/pom.xml
Original file line number Diff line number Diff line change
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;
}
8 changes: 4 additions & 4 deletions guava/module.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"group": "com.google.guava",
"module": "failureaccess",
"version": {
"requires": "1.0.2"
"requires": "1.0.3"
}
},
{
Expand Down Expand Up @@ -96,7 +96,7 @@
"group": "com.google.guava",
"module": "failureaccess",
"version": {
"requires": "1.0.2"
"requires": "1.0.3"
}
},
{
Expand Down Expand Up @@ -162,7 +162,7 @@
"group": "com.google.guava",
"module": "failureaccess",
"version": {
"requires": "1.0.2"
"requires": "1.0.3"
}
},
{
Expand Down Expand Up @@ -228,7 +228,7 @@
"group": "com.google.guava",
"module": "failureaccess",
"version": {
"requires": "1.0.2"
"requires": "1.0.3"
}
},
{
Expand Down
48 changes: 39 additions & 9 deletions guava/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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 Expand Up @@ -62,19 +62,12 @@
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Automatic-Module-Name>com.google.common</Automatic-Module-Name>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<extensions>true</extensions>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>5.1.8</version>
<version>5.1.9</version>
<executions>
<execution>
<id>bundle-manifest</id>
Expand All @@ -89,6 +82,7 @@
<Export-Package>
!com.google.common.base.internal,
!com.google.common.util.concurrent.internal,
!META-INF.*,
com.google.common.*
</Export-Package>
<Import-Package>
Expand All @@ -103,6 +97,42 @@
</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 compile 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>
<!-- https://errorprone.info/docs/installation#maven -->
<arg>-XDcompilePolicy=simple</arg>
</compilerArgs>
<multiReleaseOutput>true</multiReleaseOutput>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
Expand Down
41 changes: 41 additions & 0 deletions guava/src/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (C) 2008 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.
*/

/**
* Google Guava
*/
module com.google.common {
requires static jdk.unsupported;
requires java.logging;
requires com.google.common.util.concurrent.internal;

exports com.google.common.annotations;
exports com.google.common.base;
exports com.google.common.cache;
exports com.google.common.collect;
exports com.google.common.escape;
exports com.google.common.eventbus;
exports com.google.common.graph;
exports com.google.common.hash;
exports com.google.common.html;
exports com.google.common.io;
exports com.google.common.math;
exports com.google.common.net;
exports com.google.common.primitives;
exports com.google.common.reflect;
exports com.google.common.util.concurrent;
exports com.google.common.xml;
}
Loading

0 comments on commit 24080f8

Please sign in to comment.