Skip to content

Commit a1a45a6

Browse files
authored
Fix MavenArtifactResolver issues with maven 3.9+ (#519)
* Fix MavenArtifactResolver issues with maven 3.9+ * update workflows * fix javadoc * add dependency for maven lower than 3.9.0 * Remove unneeded maven version check
1 parent cf26b56 commit a1a45a6

File tree

5 files changed

+68
-149
lines changed

5 files changed

+68
-149
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ jobs:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- name: Checkout
15-
uses: actions/checkout@v2
15+
uses: actions/checkout@v4
1616

17-
- name: Setup Java 11 and Apache Maven
18-
uses: actions/setup-java@v1
17+
- name: Setup Java 21 and Apache Maven
18+
uses: actions/setup-java@v4
1919
with:
20-
java-version: 11
20+
distribution: 'temurin'
21+
java-version: 21
2122
server-id: ossrh
2223
server-username: MAVEN_USERNAME
2324
server-password: MAVEN_CENTRAL_TOKEN

.github/workflows/release.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@ jobs:
99
runs-on: ubuntu-latest
1010
steps:
1111
- name: Checkout
12-
uses: actions/checkout@v2
12+
uses: actions/checkout@v4
1313
with:
1414
fetch-depth: 5
1515
persist-credentials: false
1616

17-
- name: Setup Java 11 and Apache Maven
18-
uses: actions/setup-java@v1
17+
- name: Setup Java 21 and Apache Maven
18+
uses: actions/setup-java@v4
1919
with:
20-
java-version: 11
20+
distribution: 'temurin'
21+
java-version: 21
2122
server-id: ossrh
2223
server-username: MAVEN_USERNAME
2324
server-password: MAVEN_CENTRAL_TOKEN
@@ -82,7 +83,7 @@ jobs:
8283
sudo apt-get update
8384
sudo apt-get install xmlstarlet
8485
- name: Checkout
85-
uses: actions/checkout@v2
86+
uses: actions/checkout@v4
8687
with:
8788
fetch-depth: 5
8889
persist-credentials: false

pom.xml

Lines changed: 23 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
~ Copyright (c) 2019, 2023, Gluon
2+
~ Copyright (c) 2019, 2024, Gluon
33
~ All rights reserved.
44
~
55
~ Redistribution and use in source and binary forms, with or without
@@ -42,12 +42,11 @@
4242

4343
<properties>
4444
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
45-
<maven.compiler.source>11</maven.compiler.source>
46-
<maven.compiler.target>11</maven.compiler.target>
45+
<maven.compiler.resource>21</maven.compiler.resource>
4746
<source.plugin.version>3.3.0</source.plugin.version>
4847
<javadoc.plugin.version>3.5.0</javadoc.plugin.version>
4948
<gpg.plugin.version>3.1.0</gpg.plugin.version>
50-
<maven.resolver.version>1.7.3</maven.resolver.version>
49+
<maven.plugin.version>3.9.9</maven.plugin.version>
5150
<substrate.version>0.0.65-SNAPSHOT</substrate.version>
5251
</properties>
5352

@@ -60,57 +59,35 @@
6059
<dependency>
6160
<groupId>org.apache.maven</groupId>
6261
<artifactId>maven-plugin-api</artifactId>
63-
<version>3.8.8</version>
62+
<version>${maven.plugin.version}</version>
6463
<scope>provided</scope>
6564
</dependency>
66-
<dependency>
67-
<groupId>org.apache.maven.plugin-tools</groupId>
68-
<artifactId>maven-plugin-annotations</artifactId>
69-
<version>3.9.0</version>
70-
<scope>provided</scope>
71-
</dependency>
72-
<dependency>
73-
<groupId>org.codehaus.plexus</groupId>
74-
<artifactId>plexus-java</artifactId>
75-
<version>0.9.11</version>
76-
</dependency>
77-
<dependency>
78-
<groupId>org.apache.commons</groupId>
79-
<artifactId>commons-exec</artifactId>
80-
<version>1.3</version>
81-
</dependency>
8265
<dependency>
8366
<groupId>org.apache.maven</groupId>
8467
<artifactId>maven-core</artifactId>
85-
<version>3.8.8</version>
68+
<version>${maven.plugin.version}</version>
8669
<scope>provided</scope>
8770
</dependency>
8871
<dependency>
89-
<groupId>org.apache.maven.shared</groupId>
90-
<artifactId>maven-invoker</artifactId>
91-
<version>3.2.0</version>
92-
</dependency>
93-
94-
<dependency>
95-
<groupId>org.apache.maven</groupId>
96-
<artifactId>maven-aether-provider</artifactId>
97-
<version>3.3.9</version>
72+
<groupId>org.apache.maven.plugin-tools</groupId>
73+
<artifactId>maven-plugin-annotations</artifactId>
74+
<version>3.15.0</version>
9875
<scope>provided</scope>
9976
</dependency>
10077
<dependency>
10178
<groupId>org.apache.maven.resolver</groupId>
102-
<artifactId>maven-resolver-transport-http</artifactId>
103-
<version>${maven.resolver.version}</version>
79+
<artifactId>maven-resolver-util</artifactId>
80+
<version>2.0.1</version>
10481
</dependency>
10582
<dependency>
106-
<groupId>org.apache.maven.resolver</groupId>
107-
<artifactId>maven-resolver-transport-file</artifactId>
108-
<version>${maven.resolver.version}</version>
83+
<groupId>org.apache.maven.shared</groupId>
84+
<artifactId>maven-invoker</artifactId>
85+
<version>3.3.0</version>
10986
</dependency>
11087
<dependency>
111-
<groupId>org.apache.maven.resolver</groupId>
112-
<artifactId>maven-resolver-connector-basic</artifactId>
113-
<version>${maven.resolver.version}</version>
88+
<groupId>org.apache.commons</groupId>
89+
<artifactId>commons-exec</artifactId>
90+
<version>1.4.0</version>
11491
</dependency>
11592
</dependencies>
11693

@@ -134,12 +111,16 @@
134111
<plugin>
135112
<groupId>org.apache.maven.plugins</groupId>
136113
<artifactId>maven-compiler-plugin</artifactId>
137-
<version>3.11.0</version>
114+
<version>3.13.0</version>
115+
<configuration>
116+
<source>21</source>
117+
<target>21</target>
118+
</configuration>
138119
</plugin>
139120
<plugin>
140121
<groupId>org.apache.maven.plugins</groupId>
141122
<artifactId>maven-plugin-plugin</artifactId>
142-
<version>3.9.0</version>
123+
<version>3.15.0</version>
143124
</plugin>
144125
<plugin>
145126
<groupId>org.sonatype.plugins</groupId>
@@ -155,7 +136,7 @@
155136
<plugin>
156137
<groupId>org.apache.maven.plugins</groupId>
157138
<artifactId>maven-enforcer-plugin</artifactId>
158-
<version>3.4.1</version>
139+
<version>3.5.0</version>
159140
<executions>
160141
<execution>
161142
<id>enforce-no-snapshots</id>

src/main/java/com/gluonhq/NativeBaseMojo.java

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2023, Gluon
2+
* Copyright (c) 2019, 2024, Gluon
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -36,23 +36,24 @@
3636
import com.gluonhq.substrate.SubstrateDispatcher;
3737
import com.gluonhq.substrate.model.Triplet;
3838
import com.gluonhq.substrate.target.WebTargetConfiguration;
39-
import com.gluonhq.substrate.util.Version;
4039
import com.gluonhq.utils.MavenArtifactResolver;
4140
import org.apache.commons.exec.ProcessDestroyer;
4241
import org.apache.commons.exec.ShutdownHookProcessDestroyer;
4342
import org.apache.maven.artifact.Artifact;
4443
import org.apache.maven.execution.MavenSession;
4544
import org.apache.maven.model.Dependency;
46-
import org.apache.maven.model.Repository;
4745
import org.apache.maven.plugin.AbstractMojo;
4846
import org.apache.maven.plugin.BuildPluginManager;
4947
import org.apache.maven.plugin.MojoExecutionException;
5048
import org.apache.maven.plugins.annotations.Component;
5149
import org.apache.maven.plugins.annotations.Parameter;
5250
import org.apache.maven.project.MavenProject;
5351
import org.apache.maven.rtinfo.RuntimeInformation;
52+
import org.eclipse.aether.RepositorySystem;
53+
import org.eclipse.aether.RepositorySystemSession;
5454
import org.eclipse.aether.artifact.DefaultArtifact;
5555
import org.eclipse.aether.graph.DependencyFilter;
56+
import org.eclipse.aether.repository.RemoteRepository;
5657

5758
import java.io.File;
5859
import java.io.IOException;
@@ -74,14 +75,29 @@ public abstract class NativeBaseMojo extends AbstractMojo {
7475

7576
private static final List<String> ALLOWED_DEPENDENCY_TYPES = Collections.singletonList("jar");
7677

77-
// TODO: Remove this restriction when MavenArtifactResolver works with Maven 3.9.0+
78-
private static final Version MAX_SUPPORTED_MAVEN_VERSION = new Version(3, 8, 8);
79-
8078
Path outputDir;
8179

8280
@Parameter(defaultValue = "${project}", readonly = true)
8381
MavenProject project;
8482

83+
/**
84+
* The entry point to Maven Artifact Resolver
85+
*/
86+
@Component
87+
private RepositorySystem repoSystem;
88+
89+
/**
90+
* The current repository/network configuration of Maven.
91+
*/
92+
@Parameter(defaultValue = "${repositorySystemSession}", readonly = true)
93+
private RepositorySystemSession repoSession;
94+
95+
/**
96+
* The project's remote repositories to use for the resolution.
97+
*/
98+
@Parameter(defaultValue = "${project.remoteProjectRepositories}", readonly = true)
99+
private List<RemoteRepository> remoteRepos;
100+
85101
@Parameter(defaultValue = "${session}", readonly = true)
86102
MavenSession session;
87103

@@ -157,12 +173,6 @@ public abstract class NativeBaseMojo extends AbstractMojo {
157173
private ProcessDestroyer processDestroyer;
158174

159175
public SubstrateDispatcher createSubstrateDispatcher() throws IOException, MojoExecutionException {
160-
String mavenVersion = runtimeInformation.getMavenVersion();
161-
Version version = new Version(mavenVersion);
162-
if (version.compareTo(MAX_SUPPORTED_MAVEN_VERSION) > 0) {
163-
throw new MojoExecutionException("Maven version " + mavenVersion + " is not currently supported by the GluonFX Maven Plugin.\n" +
164-
"Please downgrade your Maven version to " + MAX_SUPPORTED_MAVEN_VERSION + " and then try again.\n");
165-
}
166176
if (getGraalvmHome().isEmpty()) {
167177
throw new MojoExecutionException("GraalVM installation directory not found." +
168178
" Either set GRAALVM_HOME as an environment variable or" +
@@ -242,12 +252,7 @@ private String getProjectClasspath() {
242252
}
243253

244254
private List<File> getClasspathElements(MavenProject project) {
245-
List<Repository> repositories = project.getRepositories();
246-
Repository gluonRepository = new Repository();
247-
gluonRepository.setId("Gluon");
248-
gluonRepository.setUrl("https://nexus.gluonhq.com/nexus/content/repositories/releases");
249-
repositories.add(gluonRepository);
250-
MavenArtifactResolver.initRepositories(repositories);
255+
MavenArtifactResolver.initRepositories(repoSystem, repoSession, remoteRepos);
251256

252257
List<Artifact> attachDependencies = getAttachDependencies();
253258
List<File> list = Stream.concat(project.getArtifacts().stream(), attachDependencies.stream())

0 commit comments

Comments
 (0)