Skip to content

Commit 1c5067d

Browse files
authored
build: bump build requirement to JDK 17 (#178)
* Bump build requirement to JDK 17 This change: - Bumps the build requirement for the project to JDK 17. - Adds a `java8-tests` profile that runs tests using JRE 8. The profile activates if a Maven Toolchains configuration file is present, i.e., the user knows about Maven Toolchains. Toolchains are automatically configured by `actions/setup-java`. - Bumps the version of Error Prone to a version compatible with JDK 17 (i.e., latest). - Bumps the version of Maven Surefire to a version that supports the `jdkToolchain` property. - Locks the version of the remaining plugins to the currently used versions. * Update JDKs used by CI * Add `.java-version` file * Add EOL
1 parent 78da0e9 commit 1c5067d

File tree

5 files changed

+190
-38
lines changed

5 files changed

+190
-38
lines changed

.github/workflows/maven.yml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,36 @@ name: Maven CI
22

33
on: [push, pull_request]
44

5+
permissions: read-all
6+
57
jobs:
68
build:
79
strategy:
810
matrix:
911
os: [ ubuntu-latest ]
10-
java-version: [ 8 ]
12+
java-version: [ 17 ]
1113
distro: [ 'zulu', 'temurin' ]
1214
runs-on: ${{ matrix.os }}
1315

1416
steps:
15-
- uses: actions/[email protected]
16-
- name: Set up JDK ${{ matrix.java-version }}
17+
18+
- name: Checkout repository
19+
uses: actions/[email protected]
20+
21+
- name: Set up JDK 8 and ${{ matrix.java-version }}
1722
uses: actions/setup-java@v4
1823
with:
1924
distribution: ${{ matrix.distro }}
20-
java-version: ${{ matrix.java-version }}
25+
# We install two JDKs:
26+
# * The first one is used by tests through Maven Toolchains.
27+
# * The second one is used by Maven itself to perform the build.
28+
#
29+
# WARNING: The order matters.
30+
# The last version specified will be assigned to JAVA_HOME.
31+
java-version: |
32+
8
33+
${{ matrix.java-version }}
34+
2135
- name: Build with Maven
22-
run: mvn package --file pom.xml
36+
shell: bash
37+
run: mvn verify

.java-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
17

.mvn/jvm.config

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
2+
--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
3+
--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED
4+
--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED
5+
--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
6+
--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED
7+
--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
8+
--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
9+
--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
10+
--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@
66

77
This project implements a purl parser and class for Java.
88

9+
## Requirements
10+
11+
- The library has a **runtime** requirement of JRE 8 or newer.
12+
- To **build** the library from source, you need JDK 17 or newer.
13+
914
## Compiling
15+
1016
```bash
1117
mvn clean install
1218
````

pom.xml

Lines changed: 153 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,39 @@
3737

3838
<properties>
3939
<!-- Maven Build Properties -->
40-
<maven.compiler.source>1.8</maven.compiler.source>
41-
<maven.compiler.target>1.8</maven.compiler.target>
40+
<maven.compiler.release>8</maven.compiler.release>
4241
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
4342
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
4443
<maven.javadoc.failOnError>false</maven.javadoc.failOnError>
4544

45+
<!-- Build requirements -->
46+
<!--
47+
~ Minimum JDK version required to build the library:
48+
~ Maven plugins MUST be compatible with this version.
49+
-->
50+
<min.jdk.version>17</min.jdk.version>
51+
<!--
52+
~ Upper bound for the JDK version in an official release:
53+
~ Builds MUST use a JDK version between `min.jdk.version` (inclusive) and `max.jdk.version` (exclusive)
54+
~ to be reproducible.
55+
-->
56+
<max.jdk.version>18</max.jdk.version>
57+
4658
<!-- Maven Plugin Versions -->
59+
<maven.clean.plugin.version>2.5</maven.clean.plugin.version>
4760
<maven.compiler.plugin.version>3.11.0</maven.compiler.plugin.version>
61+
<maven.deploy.plugin.version>2.7</maven.deploy.plugin.version>
62+
<maven.enforcer.plugin.version>3.4.1</maven.enforcer.plugin.version>
63+
<maven.install.plugin.version>2.4</maven.install.plugin.version>
4864
<maven.jar.plugin.version>3.3.0</maven.jar.plugin.version>
4965
<maven.javadoc.plugin.version>3.6.3</maven.javadoc.plugin.version>
5066
<maven.release.plugin.version>3.0.1</maven.release.plugin.version>
67+
<maven.resources.plugin.version>2.6</maven.resources.plugin.version>
68+
<maven.site.plugin.version>3.3</maven.site.plugin.version>
5169
<maven.source.plugin.version>3.3.0</maven.source.plugin.version>
70+
<maven.surefire.plugin.version>3.5.2</maven.surefire.plugin.version>
5271
<!-- Maven build plugins for quality checks -->
53-
<plexus.compiler.javac.errorprone.version>2.8.5</plexus.compiler.javac.errorprone.version>
54-
<error.prone.core.version>2.3.2</error.prone.core.version>
72+
<error.prone.core.version>2.36.0</error.prone.core.version>
5573
<jacoco.maven.plugin.version>0.8.11</jacoco.maven.plugin.version>
5674
<spotbugs.maven.plugin.version>4.8.3.1</spotbugs.maven.plugin.version>
5775
<com.github.spotbugs.version>4.8.3</com.github.spotbugs.version>
@@ -116,6 +134,31 @@
116134
<build>
117135
<pluginManagement>
118136
<plugins>
137+
<plugin>
138+
<groupId>org.apache.maven.plugins</groupId>
139+
<artifactId>maven-clean-plugin</artifactId>
140+
<version>${maven.clean.plugin.version}</version>
141+
</plugin>
142+
<plugin>
143+
<groupId>org.apache.maven.plugins</groupId>
144+
<artifactId>maven-compiler-plugin</artifactId>
145+
<version>${maven.compiler.plugin.version}</version>
146+
</plugin>
147+
<plugin>
148+
<groupId>org.apache.maven.plugins</groupId>
149+
<artifactId>maven-deploy-plugin</artifactId>
150+
<version>${maven.deploy.plugin.version}</version>
151+
</plugin>
152+
<plugin>
153+
<groupId>org.apache.maven.plugins</groupId>
154+
<artifactId>maven-enforcer-plugin</artifactId>
155+
<version>${maven.enforcer.plugin.version}</version>
156+
</plugin>
157+
<plugin>
158+
<groupId>org.apache.maven.plugins</groupId>
159+
<artifactId>maven-install-plugin</artifactId>
160+
<version>${maven.install.plugin.version}</version>
161+
</plugin>
119162
<plugin>
120163
<groupId>org.apache.maven.plugins</groupId>
121164
<artifactId>maven-jar-plugin</artifactId>
@@ -128,33 +171,77 @@
128171
</plugin>
129172
<plugin>
130173
<groupId>org.apache.maven.plugins</groupId>
131-
<artifactId>maven-compiler-plugin</artifactId>
132-
<version>${maven.compiler.plugin.version}</version>
133-
<configuration>
134-
<compilerId>javac-with-errorprone</compilerId>
135-
<forceJavacCompilerUse>true</forceJavacCompilerUse>
136-
<showDeprecation>true</showDeprecation>
137-
<compilerArgs>
138-
<arg>-Xlint</arg>
139-
</compilerArgs>
140-
</configuration>
141-
<dependencies>
142-
<dependency>
143-
<groupId>org.codehaus.plexus</groupId>
144-
<artifactId>plexus-compiler-javac-errorprone</artifactId>
145-
<version>${plexus.compiler.javac.errorprone.version}</version>
146-
</dependency>
147-
<!-- override plexus-compiler-javac-errorprone's dependency on Error Prone with the latest version -->
148-
<dependency>
149-
<groupId>com.google.errorprone</groupId>
150-
<artifactId>error_prone_core</artifactId>
151-
<version>${error.prone.core.version}</version>
152-
</dependency>
153-
</dependencies>
174+
<artifactId>maven-resources-plugin</artifactId>
175+
<version>${maven.resources.plugin.version}</version>
176+
</plugin>
177+
<plugin>
178+
<groupId>org.apache.maven.plugins</groupId>
179+
<artifactId>maven-site-plugin</artifactId>
180+
<version>${maven.site.plugin.version}</version>
181+
</plugin>
182+
<plugin>
183+
<groupId>org.apache.maven.plugins</groupId>
184+
<artifactId>maven-surefire-plugin</artifactId>
185+
<version>${maven.surefire.plugin.version}</version>
154186
</plugin>
155187
</plugins>
156188
</pluginManagement>
157189
<plugins>
190+
<plugin>
191+
<groupId>org.apache.maven.plugins</groupId>
192+
<artifactId>maven-enforcer-plugin</artifactId>
193+
<executions>
194+
<execution>
195+
<id>enforce-build-environment</id>
196+
<goals>
197+
<goal>enforce</goal>
198+
</goals>
199+
<configuration>
200+
<rules>
201+
<requireJavaVersion>
202+
<display>true</display>
203+
<version>[${min.jdk.version},)</version>
204+
<message>To build this library you need JDK ${min.jdk.version} or higher.</message>
205+
</requireJavaVersion>
206+
<requirePluginVersions/>
207+
</rules>
208+
</configuration>
209+
</execution>
210+
</executions>
211+
</plugin>
212+
<plugin>
213+
<groupId>org.apache.maven.plugins</groupId>
214+
<artifactId>maven-compiler-plugin</artifactId>
215+
<configuration>
216+
<release>${maven.compiler.release}</release>
217+
<showDeprecation>true</showDeprecation>
218+
<compilerArgs>
219+
<arg>-Xlint:all</arg>
220+
<!-- Error Prone plugin -->
221+
<arg>-XDcompilePolicy=simple</arg>
222+
<arg>--should-stop=ifError=FLOW</arg>
223+
<arg>-Xplugin:ErrorProne</arg>
224+
<!-- No annotation processors for now -->
225+
<arg>-proc:none</arg>
226+
</compilerArgs>
227+
<!--
228+
~ Due to the changes to annotation processor policy in JDK 23, all annotation processors
229+
~ should be mentioned explicitly.
230+
~ To add an annotation processor, add it to `annotationProcessors` below and remove
231+
~ `-proc:none` above.
232+
~
233+
~ See: https://inside.java/2024/06/18/quality-heads-up/
234+
-->
235+
<annotationProcessors/>
236+
<annotationProcessorPaths>
237+
<path>
238+
<groupId>com.google.errorprone</groupId>
239+
<artifactId>error_prone_core</artifactId>
240+
<version>${error.prone.core.version}</version>
241+
</path>
242+
</annotationProcessorPaths>
243+
</configuration>
244+
</plugin>
158245
<plugin>
159246
<groupId>com.github.spotbugs</groupId>
160247
<artifactId>spotbugs-maven-plugin</artifactId>
@@ -250,6 +337,41 @@
250337
</build>
251338

252339
<profiles>
340+
341+
<!--
342+
~ Profile to run tests using JRE 8.
343+
~
344+
~ It activates if a toolchains configuration file is present.
345+
~ See: https://maven.apache.org/guides/mini/guide-using-toolchains.html
346+
-->
347+
<profile>
348+
<id>java8-tests</id>
349+
<activation>
350+
<file>
351+
<exists>${user.home}/.m2/toolchains.xml</exists>
352+
</file>
353+
</activation>
354+
355+
<build>
356+
<plugins>
357+
<plugin>
358+
<groupId>org.apache.maven.plugins</groupId>
359+
<artifactId>maven-surefire-plugin</artifactId>
360+
<executions>
361+
<execution>
362+
<id>default-test</id>
363+
<configuration>
364+
<jdkToolchain>
365+
<version>[1.8,9)</version>
366+
</jdkToolchain>
367+
</configuration>
368+
</execution>
369+
</executions>
370+
</plugin>
371+
</plugins>
372+
</build>
373+
</profile>
374+
253375
<profile>
254376
<id>release</id>
255377
<activation>
@@ -260,17 +382,15 @@
260382
<plugin>
261383
<groupId>org.apache.maven.plugins</groupId>
262384
<artifactId>maven-enforcer-plugin</artifactId>
263-
<version>3.4.1</version>
264385
<executions>
265386
<execution>
266-
<id>enforce-java</id>
267-
<goals>
268-
<goal>enforce</goal>
269-
</goals>
387+
<id>enforce-build-environment</id>
270388
<configuration>
271389
<rules>
272390
<requireJavaVersion>
273-
<version>1.8.0</version>
391+
<display>true</display>
392+
<version>[${min.jdk.version},${max.jdk.version})</version>
393+
<message>To release this library you need JDK ${min.jdk.version}.</message>
274394
</requireJavaVersion>
275395
</rules>
276396
</configuration>

0 commit comments

Comments
 (0)