Skip to content

Commit 7a71ea0

Browse files
sgammonGoogle Java Core Libraries
authored and
Google Java Core Libraries
committed
Add module-info definition.
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: 738449919
1 parent 29b2edf commit 7a71ea0

File tree

9 files changed

+327
-43
lines changed

9 files changed

+327
-43
lines changed

android/guava-testlib/pom.xml

+39
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,45 @@
7171
</plugin>
7272
<plugin>
7373
<artifactId>maven-compiler-plugin</artifactId>
74+
<executions>
75+
<execution>
76+
<id>default-compile</id>
77+
<configuration>
78+
<compilerArgs combine.children="append" combine.self="append">
79+
<arg>-XDignore.symbol.file</arg>
80+
</compilerArgs>
81+
</configuration>
82+
</execution>
83+
<execution>
84+
<id>compile-java9</id>
85+
<phase>compile</phase>
86+
<goals>
87+
<goal>compile</goal>
88+
</goals>
89+
<configuration>
90+
<release>9</release>
91+
<compileSourceRoots>
92+
<compileSourceRoot>${project.basedir}/src</compileSourceRoot>
93+
</compileSourceRoots>
94+
95+
<!--
96+
JPMS needs access to the module sources to complete a modular Java build. We also need to override
97+
the base compiler settings (in the root `pom.xml`) to enable MRJAR output.
98+
-->
99+
<compilerArgs combine.self="override">
100+
<arg>-sourcepath</arg>
101+
<arg>${project.basedir}/src</arg>
102+
<arg>--add-reads=com.google.common=ALL-UNNAMED</arg>
103+
<arg>--add-reads=com.google.common.testlib=ALL-UNNAMED</arg>
104+
<!-- https://errorprone.info/docs/installation#maven -->
105+
<arg>-XDcompilePolicy=simple</arg>
106+
<arg>-Xlint:-removal</arg>
107+
<arg>-Xlint:-options</arg>
108+
</compilerArgs>
109+
<multiReleaseOutput>true</multiReleaseOutput>
110+
</configuration>
111+
</execution>
112+
</executions>
74113
</plugin>
75114
<plugin>
76115
<artifactId>maven-source-plugin</artifactId>

android/guava/pom.xml

+39-7
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,6 @@
6262
</plugin>
6363
<plugin>
6464
<artifactId>maven-jar-plugin</artifactId>
65-
<configuration>
66-
<archive>
67-
<manifestEntries>
68-
<Automatic-Module-Name>com.google.common</Automatic-Module-Name>
69-
</manifestEntries>
70-
</archive>
71-
</configuration>
7265
</plugin>
7366
<plugin>
7467
<extensions>true</extensions>
@@ -86,9 +79,12 @@
8679
</executions>
8780
<configuration>
8881
<instructions>
82+
<!-- Silence a warning that claims that META-INF/versions/9/... is the "wrong directory" for our classes. -->
83+
<_fixupmessages>^Classes found in the wrong directory: .*</_fixupmessages>
8984
<Export-Package>
9085
!com.google.common.base.internal,
9186
!com.google.common.util.concurrent.internal,
87+
!META-INF.*,
9288
com.google.common.*
9389
</Export-Package>
9490
<Import-Package>
@@ -103,6 +99,42 @@
10399
</plugin>
104100
<plugin>
105101
<artifactId>maven-compiler-plugin</artifactId>
102+
<executions>
103+
<execution>
104+
<id>default-compile</id>
105+
<configuration>
106+
<compilerArgs combine.children="append" combine.self="append">
107+
<arg>-XDignore.symbol.file</arg>
108+
</compilerArgs>
109+
</configuration>
110+
</execution>
111+
<execution>
112+
<id>compile-java9</id>
113+
<phase>compile</phase>
114+
<goals>
115+
<goal>compile</goal>
116+
</goals>
117+
<configuration>
118+
<release>9</release>
119+
<compileSourceRoots>
120+
<compileSourceRoot>${project.basedir}/src</compileSourceRoot>
121+
</compileSourceRoots>
122+
123+
<!--
124+
JPMS needs access to the module sources to complete a modular Java build. We also need to override the
125+
base compile settings (in the root `pom.xml`) to enable MRJAR output.
126+
-->
127+
<compilerArgs combine.self="override">
128+
<arg>-sourcepath</arg>
129+
<arg>${project.basedir}/src</arg>
130+
<arg>--add-reads=com.google.common=ALL-UNNAMED</arg>
131+
<!-- https://errorprone.info/docs/installation#maven -->
132+
<arg>-XDcompilePolicy=simple</arg>
133+
</compilerArgs>
134+
<multiReleaseOutput>true</multiReleaseOutput>
135+
</configuration>
136+
</execution>
137+
</executions>
106138
</plugin>
107139
<plugin>
108140
<artifactId>maven-source-plugin</artifactId>

android/pom.xml

+45-10
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,7 @@
145145
<target>1.8</target>
146146
<encoding>UTF-8</encoding>
147147
<parameters>true</parameters>
148-
<compilerArgs>
149-
<!--
150-
Make includes/excludes fully work:
151-
https://issues.apache.org/jira/browse/MCOMPILER-174
152-
153-
(Compare what guava-gwt has to do for maven-javadoc-plugin.)
154-
-->
155-
<arg>-sourcepath</arg>
156-
<arg>doesnotexist</arg>
148+
<compilerArgs combine.children="override">
157149
<!-- https://errorprone.info/docs/installation#maven -->
158150
<arg>-XDcompilePolicy=simple</arg>
159151
<arg>--should-stop=ifError=FLOW</arg>
@@ -181,6 +173,7 @@
181173
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED</arg>
182174
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED</arg>
183175
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED</arg>
176+
<arg>-Xlint:-removal,-options</arg>
184177
</compilerArgs>
185178
<annotationProcessorPaths>
186179
<path>
@@ -192,6 +185,35 @@
192185
<!-- Fork because we need args like add-exports. (But see the TODO above about .mvn/jvm.config.) -->
193186
<fork>true</fork>
194187
</configuration>
188+
<executions>
189+
<execution>
190+
<id>default-compile</id>
191+
<configuration>
192+
<source>1.8</source>
193+
<target>1.8</target>
194+
<excludes>
195+
<exclude>module-info.java</exclude>
196+
</excludes>
197+
<compilerArgs>
198+
<!--
199+
Make includes/excludes fully work:
200+
https://issues.apache.org/jira/browse/MCOMPILER-174
201+
(Compare what guava-gwt has to do for maven-javadoc-plugin.)
202+
-->
203+
<arg>-sourcepath</arg>
204+
<arg>doesnotexist</arg>
205+
</compilerArgs>
206+
</configuration>
207+
</execution>
208+
<execution>
209+
<id>default-testCompile</id>
210+
<configuration>
211+
<compilerArgs>
212+
<compilerArg>-Xlint:-removal</compilerArg>
213+
</compilerArgs>
214+
</configuration>
215+
</execution>
216+
</executions>
195217
</plugin>
196218
<plugin>
197219
<artifactId>maven-dependency-plugin</artifactId>
@@ -211,7 +233,20 @@
211233
</plugin>
212234
<plugin>
213235
<artifactId>maven-jar-plugin</artifactId>
214-
<version>3.2.0</version>
236+
<version>3.4.0</version>
237+
<configuration>
238+
<excludes>
239+
<!-- The root module (where applicable) is withheld because it is provided at `META-INF/versions/9/`. -->
240+
<exclude>/module-info.class</exclude>
241+
<!-- Avoid duplicating compiled classes within the `META-INF/versions/9/` root. -->
242+
<exclude>META-INF/versions/9/com/**/*.class</exclude>
243+
</excludes>
244+
<archive>
245+
<manifestEntries>
246+
<Multi-Release>true</Multi-Release>
247+
</manifestEntries>
248+
</archive>
249+
</configuration>
215250
</plugin>
216251
<plugin>
217252
<artifactId>maven-javadoc-plugin</artifactId>

guava-gwt/pom.xml

+14-9
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,20 @@
134134
</plugin>
135135
<plugin>
136136
<artifactId>maven-compiler-plugin</artifactId>
137-
<configuration>
138-
<excludes>
139-
<!-- Yes, we want to exclude ForceGuavaCompilation 4 times: -->
140-
<!-- (And we might as well exclude DummyJavadocClass 3 times (though it would be harmless to include).) -->
141-
<!-- 1. Don't compile it (since that requires a *non-test* dep on gwt-user. -->
142-
<exclude>**/ForceGuavaCompilation*</exclude>
143-
<exclude>**/DummyJavadocClass*</exclude>
144-
</excludes>
145-
</configuration>
137+
<executions>
138+
<execution>
139+
<id>default-compile</id>
140+
<configuration>
141+
<excludes>
142+
<!-- Yes, we want to exclude ForceGuavaCompilation 4 times: -->
143+
<!-- (And we might as well exclude DummyJavadocClass 3 times (though it would be harmless to include).) -->
144+
<!-- 1. Don't compile it (since that requires a *non-test* dep on gwt-user. -->
145+
<exclude>**/ForceGuavaCompilation*</exclude>
146+
<exclude>**/DummyJavadocClass*</exclude>
147+
</excludes>
148+
</configuration>
149+
</execution>
150+
</executions>
146151
</plugin>
147152
<plugin>
148153
<artifactId>maven-jar-plugin</artifactId>

guava-testlib/pom.xml

+39
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,45 @@
7171
</plugin>
7272
<plugin>
7373
<artifactId>maven-compiler-plugin</artifactId>
74+
<executions>
75+
<execution>
76+
<id>default-compile</id>
77+
<configuration>
78+
<compilerArgs combine.children="append" combine.self="append">
79+
<arg>-XDignore.symbol.file</arg>
80+
</compilerArgs>
81+
</configuration>
82+
</execution>
83+
<execution>
84+
<id>compile-java9</id>
85+
<phase>compile</phase>
86+
<goals>
87+
<goal>compile</goal>
88+
</goals>
89+
<configuration>
90+
<release>9</release>
91+
<compileSourceRoots>
92+
<compileSourceRoot>${project.basedir}/src</compileSourceRoot>
93+
</compileSourceRoots>
94+
95+
<!--
96+
JPMS needs access to the module sources to complete a modular Java build. We also need to override
97+
the base compiler settings (in the root `pom.xml`) to enable MRJAR output.
98+
-->
99+
<compilerArgs combine.self="override">
100+
<arg>-sourcepath</arg>
101+
<arg>${project.basedir}/src</arg>
102+
<arg>--add-reads=com.google.common=ALL-UNNAMED</arg>
103+
<arg>--add-reads=com.google.common.testlib=ALL-UNNAMED</arg>
104+
<!-- https://errorprone.info/docs/installation#maven -->
105+
<arg>-XDcompilePolicy=simple</arg>
106+
<arg>-Xlint:-removal</arg>
107+
<arg>-Xlint:-options</arg>
108+
</compilerArgs>
109+
<multiReleaseOutput>true</multiReleaseOutput>
110+
</configuration>
111+
</execution>
112+
</executions>
74113
</plugin>
75114
<plugin>
76115
<artifactId>maven-source-plugin</artifactId>

guava-testlib/src/module-info.java

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (C) 2024 The Guava Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+
* in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License
10+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+
* or implied. See the License for the specific language governing permissions and limitations under
12+
* the License.
13+
*/
14+
15+
/** Guava Testlib */
16+
module com.google.common.testlib {
17+
requires java.logging;
18+
requires com.google.common;
19+
requires com.google.common.util.concurrent.internal;
20+
21+
exports com.google.common.collect.testing;
22+
exports com.google.common.collect.testing.features;
23+
exports com.google.common.collect.testing.google;
24+
exports com.google.common.collect.testing.testers;
25+
exports com.google.common.escape.testing;
26+
exports com.google.common.testing;
27+
exports com.google.common.util.concurrent.testing;
28+
}

guava/pom.xml

+39-7
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,6 @@
6262
</plugin>
6363
<plugin>
6464
<artifactId>maven-jar-plugin</artifactId>
65-
<configuration>
66-
<archive>
67-
<manifestEntries>
68-
<Automatic-Module-Name>com.google.common</Automatic-Module-Name>
69-
</manifestEntries>
70-
</archive>
71-
</configuration>
7265
</plugin>
7366
<plugin>
7467
<extensions>true</extensions>
@@ -86,9 +79,12 @@
8679
</executions>
8780
<configuration>
8881
<instructions>
82+
<!-- Silence a warning that claims that META-INF/versions/9/... is the "wrong directory" for our classes. -->
83+
<_fixupmessages>^Classes found in the wrong directory: .*</_fixupmessages>
8984
<Export-Package>
9085
!com.google.common.base.internal,
9186
!com.google.common.util.concurrent.internal,
87+
!META-INF.*,
9288
com.google.common.*
9389
</Export-Package>
9490
<Import-Package>
@@ -103,6 +99,42 @@
10399
</plugin>
104100
<plugin>
105101
<artifactId>maven-compiler-plugin</artifactId>
102+
<executions>
103+
<execution>
104+
<id>default-compile</id>
105+
<configuration>
106+
<compilerArgs combine.children="append" combine.self="append">
107+
<arg>-XDignore.symbol.file</arg>
108+
</compilerArgs>
109+
</configuration>
110+
</execution>
111+
<execution>
112+
<id>compile-java9</id>
113+
<phase>compile</phase>
114+
<goals>
115+
<goal>compile</goal>
116+
</goals>
117+
<configuration>
118+
<release>9</release>
119+
<compileSourceRoots>
120+
<compileSourceRoot>${project.basedir}/src</compileSourceRoot>
121+
</compileSourceRoots>
122+
123+
<!--
124+
JPMS needs access to the module sources to complete a modular Java build. We also need to override the
125+
base compile settings (in the root `pom.xml`) to enable MRJAR output.
126+
-->
127+
<compilerArgs combine.self="override">
128+
<arg>-sourcepath</arg>
129+
<arg>${project.basedir}/src</arg>
130+
<arg>--add-reads=com.google.common=ALL-UNNAMED</arg>
131+
<!-- https://errorprone.info/docs/installation#maven -->
132+
<arg>-XDcompilePolicy=simple</arg>
133+
</compilerArgs>
134+
<multiReleaseOutput>true</multiReleaseOutput>
135+
</configuration>
136+
</execution>
137+
</executions>
106138
</plugin>
107139
<plugin>
108140
<artifactId>maven-source-plugin</artifactId>

0 commit comments

Comments
 (0)