Skip to content

Commit 00e8957

Browse files
committed
Add Java module system support with Multi-Release JAR
Add module-info.java files to all modules and configure Multi-Release JAR compilation to support both Java 8 (without modules) and Java 9+ (with modules). - Add module declarations for common, service, value, and factory modules - Configure Maven compiler for dual compilation (release=8 and release=9) - Update build order and versions for consistency - Maintain full backward compatibility with Java 8 runtime Enables module system benefits for Java 9+ users while preserving existing Java 8 compatibility through Multi-Release JAR mechanism.
1 parent 34fc51b commit 00e8957

File tree

17 files changed

+335
-53
lines changed

17 files changed

+335
-53
lines changed

build-pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
<packaging>pom</packaging>
88
<modules>
99
<module>common</module>
10-
<module>factory</module>
1110
<module>service</module>
1211
<module>value</module>
12+
<module>factory</module>
1313
</modules>
1414
<distributionManagement>
1515
<repository>

common/pom.xml

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
<groupId>com.google.auto</groupId>
2222
<artifactId>auto-common</artifactId>
23-
<version>HEAD-SNAPSHOT</version>
23+
<version>999.0.0-SNAPSHOT</version>
2424
<name>Auto Common Libraries</name>
2525
<description>
2626
Common utilities for creating annotation processors.
@@ -29,7 +29,6 @@
2929

3030
<properties>
3131
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
32-
<java.version>1.8</java.version>
3332
<guava.version>33.5.0-jre</guava.version>
3433
<truth.version>1.4.5</truth.version>
3534
</properties>
@@ -111,17 +110,42 @@
111110
<artifactId>maven-compiler-plugin</artifactId>
112111
<version>3.14.0</version>
113112
<configuration>
114-
<source>${java.version}</source>
115-
<target>${java.version}</target>
116113
<compilerArgument>-Xlint:all</compilerArgument>
117114
<showWarnings>true</showWarnings>
118115
<showDeprecation>true</showDeprecation>
119116
<testExcludes combine.children="append" />
120117
</configuration>
118+
<executions>
119+
<execution>
120+
<id>default-compile</id>
121+
<configuration>
122+
<release>9</release>
123+
</configuration>
124+
</execution>
125+
<execution>
126+
<id>base-compile</id>
127+
<goals>
128+
<goal>compile</goal>
129+
</goals>
130+
<configuration>
131+
<excludes>
132+
<exclude>module-info.java</exclude>
133+
</excludes>
134+
<release>8</release>
135+
</configuration>
136+
</execution>
137+
</executions>
121138
</plugin>
122139
<plugin>
123140
<artifactId>maven-jar-plugin</artifactId>
124141
<version>3.4.2</version>
142+
<configuration>
143+
<archive>
144+
<manifestEntries>
145+
<Multi-Release>true</Multi-Release>
146+
</manifestEntries>
147+
</archive>
148+
</configuration>
125149
</plugin>
126150
<plugin>
127151
<artifactId>maven-javadoc-plugin</artifactId>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* Common utilities for creating annotation processors.
19+
*/
20+
module com.google.auto.common {
21+
requires transitive com.google.common;
22+
requires transitive org.jspecify;
23+
requires transitive java.compiler;
24+
requires static com.squareup.javapoet;
25+
26+
exports com.google.auto.common;
27+
}

factory/pom.xml

Lines changed: 65 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
<groupId>com.google.auto.factory</groupId>
2323
<artifactId>auto-factory</artifactId>
24-
<version>HEAD-SNAPSHOT</version>
24+
<version>999.0.0-SNAPSHOT</version>
2525
<name>AutoFactory</name>
2626
<description>
2727
JSR-330-compatible factories.
@@ -30,9 +30,8 @@
3030

3131
<properties>
3232
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
33-
<auto-service.version>1.1.1</auto-service.version>
34-
<auto-value.version>1.11.0</auto-value.version>
35-
<java.version>1.8</java.version>
33+
<auto-service.version>999.0.0-SNAPSHOT</auto-service.version>
34+
<auto-value.version>999.0.0-SNAPSHOT</auto-value.version>
3635
<guava.version>33.5.0-jre</guava.version>
3736
<truth.version>1.4.5</truth.version>
3837
</properties>
@@ -95,7 +94,7 @@
9594
<dependency>
9695
<groupId>com.google.auto</groupId>
9796
<artifactId>auto-common</artifactId>
98-
<version>1.2.2</version>
97+
<version>999.0.0-SNAPSHOT</version>
9998
</dependency>
10099
<dependency>
101100
<groupId>com.google.auto.value</groupId>
@@ -180,8 +179,6 @@
180179
<artifactId>maven-compiler-plugin</artifactId>
181180
<version>3.14.0</version>
182181
<configuration>
183-
<source>${java.version}</source>
184-
<target>${java.version}</target>
185182
<compilerArgument>-Xlint:all</compilerArgument>
186183
<showWarnings>true</showWarnings>
187184
<showDeprecation>true</showDeprecation>
@@ -203,6 +200,60 @@
203200
</path>
204201
</annotationProcessorPaths>
205202
</configuration>
203+
<executions>
204+
<execution>
205+
<id>default-compile</id>
206+
<configuration>
207+
<release>9</release>
208+
<annotationProcessorPaths>
209+
<path>
210+
<groupId>com.google.auto.service</groupId>
211+
<artifactId>auto-service</artifactId>
212+
<version>${auto-service.version}</version>
213+
</path>
214+
<path>
215+
<groupId>com.google.auto.value</groupId>
216+
<artifactId>auto-value</artifactId>
217+
<version>${auto-value.version}</version>
218+
</path>
219+
<path>
220+
<groupId>net.ltgt.gradle.incap</groupId>
221+
<artifactId>incap-processor</artifactId>
222+
<version>1.0.0</version>
223+
</path>
224+
</annotationProcessorPaths>
225+
</configuration>
226+
</execution>
227+
<execution>
228+
<id>base-compile</id>
229+
<goals>
230+
<goal>compile</goal>
231+
</goals>
232+
<configuration>
233+
<excludes>
234+
<exclude>module-info.java</exclude>
235+
</excludes>
236+
<release>8</release>
237+
<annotationProcessorPaths>
238+
<path>
239+
<groupId>com.google.auto.service</groupId>
240+
<artifactId>auto-service</artifactId>
241+
<version>${auto-service.version}</version>
242+
</path>
243+
<path>
244+
<groupId>com.google.auto.value</groupId>
245+
<artifactId>auto-value</artifactId>
246+
<version>${auto-value.version}</version>
247+
</path>
248+
<path>
249+
<groupId>net.ltgt.gradle.incap</groupId>
250+
<artifactId>incap-processor</artifactId>
251+
<version>1.0.0</version>
252+
</path>
253+
</annotationProcessorPaths>
254+
</configuration>
255+
</execution>
256+
</executions>
206257
</plugin>
207258
<plugin>
208259
<artifactId>maven-javadoc-plugin</artifactId>
@@ -241,6 +292,13 @@
241292
<plugin>
242293
<artifactId>maven-jar-plugin</artifactId>
243294
<version>3.4.2</version>
295+
<configuration>
296+
<archive>
297+
<manifestEntries>
298+
<Multi-Release>true</Multi-Release>
299+
</manifestEntries>
300+
</archive>
301+
</configuration>
244302
</plugin>
245303
<plugin>
246304
<artifactId>maven-invoker-plugin</artifactId>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* JSR-330-compatible factories.
19+
*/
20+
module com.google.auto.factory {
21+
requires com.google.auto.common;
22+
requires com.google.auto.service;
23+
requires com.google.auto.value.annotations;
24+
requires incap;
25+
requires com.squareup.javapoet;
26+
requires java.compiler;
27+
28+
exports com.google.auto.factory;
29+
exports com.google.auto.factory.processor;
30+
31+
provides javax.annotation.processing.Processor
32+
with com.google.auto.factory.processor.AutoFactoryProcessor;
33+
}

service/annotations/pom.xml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,11 @@
2121
<parent>
2222
<groupId>com.google.auto.service</groupId>
2323
<artifactId>auto-service-aggregator</artifactId>
24-
<version>HEAD-SNAPSHOT</version>
24+
<version>999.0.0-SNAPSHOT</version>
2525
</parent>
2626

2727
<groupId>com.google.auto.service</groupId>
2828
<artifactId>auto-service-annotations</artifactId>
29-
<version>HEAD-SNAPSHOT</version>
3029
<name>AutoService</name>
3130
<description>
3231
Provider-configuration files for ServiceLoader.
@@ -44,21 +43,12 @@
4443
<plugins>
4544
<plugin>
4645
<artifactId>maven-jar-plugin</artifactId>
47-
<configuration>
48-
<archive>
49-
<manifestEntries>
50-
<Automatic-Module-Name>com.google.auto.service</Automatic-Module-Name>
51-
</manifestEntries>
52-
</archive>
53-
</configuration>
5446
</plugin>
5547
<plugin>
5648
<artifactId>maven-compiler-plugin</artifactId>
5749
<configuration>
5850
<!-- disable processing because the definition in META-INF/services breaks javac -->
5951
<compilerArgument>-proc:none</compilerArgument>
60-
<source>1.8</source>
61-
<target>1.8</target>
6252
</configuration>
6353
</plugin>
6454
</plugins>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* Provider-configuration files for ServiceLoader.
19+
*/
20+
module com.google.auto.service {
21+
exports com.google.auto.service;
22+
}

service/pom.xml

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
<groupId>com.google.auto.service</groupId>
2222
<artifactId>auto-service-aggregator</artifactId>
23-
<version>HEAD-SNAPSHOT</version>
23+
<version>999.0.0-SNAPSHOT</version>
2424
<name>AutoService Aggregator</name>
2525
<description>
2626
Aggregator POM for @AutoService
@@ -30,7 +30,6 @@
3030

3131
<properties>
3232
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
33-
<java.version>1.8</java.version>
3433
<guava.version>33.5.0-jre</guava.version>
3534
<truth.version>1.4.5</truth.version>
3635
</properties>
@@ -106,16 +105,41 @@
106105
<artifactId>maven-compiler-plugin</artifactId>
107106
<version>3.14.0</version>
108107
<configuration>
109-
<source>${java.version}</source>
110-
<target>${java.version}</target>
111108
<compilerArgument>-Xlint:all</compilerArgument>
112109
<showWarnings>true</showWarnings>
113110
<showDeprecation>true</showDeprecation>
114111
</configuration>
112+
<executions>
113+
<execution>
114+
<id>default-compile</id>
115+
<configuration>
116+
<release>9</release>
117+
</configuration>
118+
</execution>
119+
<execution>
120+
<id>base-compile</id>
121+
<goals>
122+
<goal>compile</goal>
123+
</goals>
124+
<configuration>
125+
<excludes>
126+
<exclude>module-info.java</exclude>
127+
</excludes>
128+
<release>8</release>
129+
</configuration>
130+
</execution>
131+
</executions>
115132
</plugin>
116133
<plugin>
117134
<artifactId>maven-jar-plugin</artifactId>
118135
<version>3.4.2</version>
136+
<configuration>
137+
<archive>
138+
<manifestEntries>
139+
<Multi-Release>true</Multi-Release>
140+
</manifestEntries>
141+
</archive>
142+
</configuration>
119143
</plugin>
120144
</plugins>
121145
</pluginManagement>

service/processor/pom.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,11 @@
2121
<parent>
2222
<groupId>com.google.auto.service</groupId>
2323
<artifactId>auto-service-aggregator</artifactId>
24-
<version>HEAD-SNAPSHOT</version>
24+
<version>999.0.0-SNAPSHOT</version>
2525
</parent>
2626

2727
<groupId>com.google.auto.service</groupId>
2828
<artifactId>auto-service</artifactId>
29-
<version>HEAD-SNAPSHOT</version>
3029
<name>AutoService Processor</name>
3130
<description>
3231
Provider-configuration files for ServiceLoader.
@@ -49,7 +48,7 @@
4948
<dependency>
5049
<groupId>com.google.auto</groupId>
5150
<artifactId>auto-common</artifactId>
52-
<version>1.2.2</version>
51+
<version>999.0.0-SNAPSHOT</version>
5352
</dependency>
5453
<dependency>
5554
<groupId>com.google.guava</groupId>

0 commit comments

Comments
 (0)