Skip to content

Commit

Permalink
Add module-info definition.
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.

- Fixes #2970
- Fixes #7094

Relates-To: elide-dev/jpms#1
Signed-off-by: Sam Gammon <[email protected]>
RELNOTES=Changed the Guava jar (and guava-testlib jar) to be a modular jar.
PiperOrigin-RevId: 725281837
  • Loading branch information
sgammon authored and Google Java Core Libraries committed Feb 12, 2025
1 parent 287c701 commit f556e93
Show file tree
Hide file tree
Showing 12 changed files with 331 additions and 47 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
39 changes: 39 additions & 0 deletions android/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">
<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
50 changes: 41 additions & 9 deletions 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 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 @@ -86,9 +79,12 @@
</executions>
<configuration>
<instructions>
<!-- Silence a warning that claims that META-INF/versions/9/... is the "wrong directory" for our classes. -->
<_fixupmessages>^Classes found in the wrong directory: .*</_fixupmessages>
<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 +99,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">
<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
55 changes: 45 additions & 10 deletions android/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,7 @@
<target>1.8</target>
<encoding>UTF-8</encoding>
<parameters>true</parameters>
<compilerArgs>
<!--
Make includes/excludes fully work:
https://issues.apache.org/jira/browse/MCOMPILER-174
(Compare what guava-gwt has to do for maven-javadoc-plugin.)
-->
<arg>-sourcepath</arg>
<arg>doesnotexist</arg>
<compilerArgs combine.children="override">
<!-- https://errorprone.info/docs/installation#maven -->
<arg>-XDcompilePolicy=simple</arg>
<arg>--should-stop=ifError=FLOW</arg>
Expand Down Expand Up @@ -181,6 +173,7 @@
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED</arg>
<arg>-Xlint:-removal,-options</arg>
</compilerArgs>
<annotationProcessorPaths>
<path>
Expand All @@ -192,6 +185,35 @@
<!-- Fork because we need args like add-exports. (But see the TODO above about .mvn/jvm.config.) -->
<fork>true</fork>
</configuration>
<executions>
<execution>
<id>default-compile</id>
<configuration>
<source>1.8</source>
<target>1.8</target>
<excludes>
<exclude>module-info.java</exclude>
</excludes>
<compilerArgs>
<!--
Make includes/excludes fully work:
https://issues.apache.org/jira/browse/MCOMPILER-174
(Compare what guava-gwt has to do for maven-javadoc-plugin.)
-->
<arg>-sourcepath</arg>
<arg>doesnotexist</arg>
</compilerArgs>
</configuration>
</execution>
<execution>
<id>default-testCompile</id>
<configuration>
<compilerArgs>
<compilerArg>-Xlint:-removal</compilerArg>
</compilerArgs>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
Expand All @@ -211,7 +233,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
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">
<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
28 changes: 28 additions & 0 deletions guava-testlib/src/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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 */
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
Loading

0 comments on commit f556e93

Please sign in to comment.