Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,36 @@ name: Maven CI

on: [push, pull_request]

permissions: read-all

jobs:
build:
strategy:
matrix:
os: [ ubuntu-latest ]
java-version: [ 8 ]
java-version: [ 17 ]
distro: [ 'zulu', 'temurin' ]
runs-on: ${{ matrix.os }}

steps:
- uses: actions/[email protected]
- name: Set up JDK ${{ matrix.java-version }}

- name: Checkout repository
uses: actions/[email protected]

- name: Set up JDK 8 and ${{ matrix.java-version }}
uses: actions/setup-java@v4
with:
distribution: ${{ matrix.distro }}
java-version: ${{ matrix.java-version }}
# We install two JDKs:
# * The first one is used by tests through Maven Toolchains.
# * The second one is used by Maven itself to perform the build.
#
# WARNING: The order matters.
# The last version specified will be assigned to JAVA_HOME.
java-version: |
8
${{ matrix.java-version }}

- name: Build with Maven
run: mvn package --file pom.xml
shell: bash
run: mvn verify
1 change: 1 addition & 0 deletions .java-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
17
10 changes: 10 additions & 0 deletions .mvn/jvm.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@

This project implements a purl parser and class for Java.

## Requirements

- The library has a **runtime** requirement of JRE 8 or newer.
- To **build** the library from source, you need JDK 17 or newer.

## Compiling

```bash
mvn clean install
````
Expand Down
186 changes: 153 additions & 33 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,39 @@

<properties>
<!-- Maven Build Properties -->
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.release>8</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.javadoc.failOnError>false</maven.javadoc.failOnError>

<!-- Build requirements -->
<!--
~ Minimum JDK version required to build the library:
~ Maven plugins MUST be compatible with this version.
-->
<min.jdk.version>17</min.jdk.version>
<!--
~ Upper bound for the JDK version in an official release:
~ Builds MUST use a JDK version between `min.jdk.version` (inclusive) and `max.jdk.version` (exclusive)
~ to be reproducible.
-->
<max.jdk.version>18</max.jdk.version>

<!-- Maven Plugin Versions -->
<maven.clean.plugin.version>2.5</maven.clean.plugin.version>
<maven.compiler.plugin.version>3.11.0</maven.compiler.plugin.version>
<maven.deploy.plugin.version>2.7</maven.deploy.plugin.version>
<maven.enforcer.plugin.version>3.4.1</maven.enforcer.plugin.version>
<maven.install.plugin.version>2.4</maven.install.plugin.version>
<maven.jar.plugin.version>3.3.0</maven.jar.plugin.version>
<maven.javadoc.plugin.version>3.6.3</maven.javadoc.plugin.version>
<maven.release.plugin.version>3.0.1</maven.release.plugin.version>
<maven.resources.plugin.version>2.6</maven.resources.plugin.version>
<maven.site.plugin.version>3.3</maven.site.plugin.version>
<maven.source.plugin.version>3.3.0</maven.source.plugin.version>
<maven.surefire.plugin.version>3.5.2</maven.surefire.plugin.version>
<!-- Maven build plugins for quality checks -->
<plexus.compiler.javac.errorprone.version>2.8.5</plexus.compiler.javac.errorprone.version>
<error.prone.core.version>2.3.2</error.prone.core.version>
<error.prone.core.version>2.36.0</error.prone.core.version>
<jacoco.maven.plugin.version>0.8.11</jacoco.maven.plugin.version>
<spotbugs.maven.plugin.version>4.8.3.1</spotbugs.maven.plugin.version>
<com.github.spotbugs.version>4.8.3</com.github.spotbugs.version>
Expand Down Expand Up @@ -116,6 +134,31 @@
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>${maven.clean.plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>${maven.deploy.plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>${maven.enforcer.plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>${maven.install.plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
Expand All @@ -128,33 +171,77 @@
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<compilerId>javac-with-errorprone</compilerId>
<forceJavacCompilerUse>true</forceJavacCompilerUse>
<showDeprecation>true</showDeprecation>
<compilerArgs>
<arg>-Xlint</arg>
</compilerArgs>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-javac-errorprone</artifactId>
<version>${plexus.compiler.javac.errorprone.version}</version>
</dependency>
<!-- override plexus-compiler-javac-errorprone's dependency on Error Prone with the latest version -->
<dependency>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_core</artifactId>
<version>${error.prone.core.version}</version>
</dependency>
</dependencies>
<artifactId>maven-resources-plugin</artifactId>
<version>${maven.resources.plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>${maven.site.plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<executions>
<execution>
<id>enforce-build-environment</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireJavaVersion>
<display>true</display>
<version>[${min.jdk.version},)</version>
<message>To build this library you need JDK ${min.jdk.version} or higher.</message>
</requireJavaVersion>
<requirePluginVersions/>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<release>${maven.compiler.release}</release>
<showDeprecation>true</showDeprecation>
<compilerArgs>
<arg>-Xlint:all</arg>
<!-- Error Prone plugin -->
<arg>-XDcompilePolicy=simple</arg>
<arg>--should-stop=ifError=FLOW</arg>
<arg>-Xplugin:ErrorProne</arg>
<!-- No annotation processors for now -->
<arg>-proc:none</arg>
</compilerArgs>
<!--
~ Due to the changes to annotation processor policy in JDK 23, all annotation processors
~ should be mentioned explicitly.
~ To add an annotation processor, add it to `annotationProcessors` below and remove
~ `-proc:none` above.
~
~ See: https://inside.java/2024/06/18/quality-heads-up/
-->
<annotationProcessors/>
<annotationProcessorPaths>
<path>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_core</artifactId>
<version>${error.prone.core.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
Expand Down Expand Up @@ -250,6 +337,41 @@
</build>

<profiles>

<!--
~ Profile to run tests using JRE 8.
~
~ It activates if a toolchains configuration file is present.
~ See: https://maven.apache.org/guides/mini/guide-using-toolchains.html
-->
<profile>
<id>java8-tests</id>
<activation>
<file>
<exists>${user.home}/.m2/toolchains.xml</exists>
</file>
</activation>
Comment on lines +347 to +353
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not understand this profile. If the build requires Java 17, how could this be activated and work? What am I missing?

Copy link
Contributor Author

@ppkarwasz ppkarwasz Mar 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The purpose of this profile is to run tests using JRE 8 in forked JVMs.
Since this can be only done through Maven Toolchains, which might be hard to configure for single-time contributors, the profile only activates if a toolchains configuration is present.

Note that the CI always has a toolchains configuration.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it - I've never set the Maven Toolchain up. Thanks for the explanation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hadn't really used it either, but since GitHub automatically sets up the file, it's pretty painless.

I think this pull request makes it so that it's not required (presumably, the CI will test Java 8 if the developer does not), but if you're interested, it has a mojo to automatically try to generate the config file mvn toolchains:generate-jdk-toolchains-xml.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! 💯
It discovered all 8 JDKs installed on my system.


<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>default-test</id>
<configuration>
<jdkToolchain>
<version>[1.8,9)</version>
</jdkToolchain>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

<profile>
<id>release</id>
<activation>
Expand All @@ -260,17 +382,15 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.4.1</version>
<executions>
<execution>
<id>enforce-java</id>
<goals>
<goal>enforce</goal>
</goals>
<id>enforce-build-environment</id>
<configuration>
<rules>
<requireJavaVersion>
<version>1.8.0</version>
<display>true</display>
<version>[${min.jdk.version},${max.jdk.version})</version>
<message>To release this library you need JDK ${min.jdk.version}.</message>
</requireJavaVersion>
</rules>
</configuration>
Expand Down