Skip to content

Commit

Permalink
Fix MavenArtifactResolver issues with maven 3.9+ (#519)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jperedadnr authored Oct 15, 2024
1 parent cf26b56 commit a1a45a6
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 149 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup Java 11 and Apache Maven
uses: actions/setup-java@v1
- name: Setup Java 21 and Apache Maven
uses: actions/setup-java@v4
with:
java-version: 11
distribution: 'temurin'
java-version: 21
server-id: ossrh
server-username: MAVEN_USERNAME
server-password: MAVEN_CENTRAL_TOKEN
Expand Down
11 changes: 6 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 5
persist-credentials: false

- name: Setup Java 11 and Apache Maven
uses: actions/setup-java@v1
- name: Setup Java 21 and Apache Maven
uses: actions/setup-java@v4
with:
java-version: 11
distribution: 'temurin'
java-version: 21
server-id: ossrh
server-username: MAVEN_USERNAME
server-password: MAVEN_CENTRAL_TOKEN
Expand Down Expand Up @@ -82,7 +83,7 @@ jobs:
sudo apt-get update
sudo apt-get install xmlstarlet
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 5
persist-credentials: false
Expand Down
65 changes: 23 additions & 42 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
~ Copyright (c) 2019, 2023, Gluon
~ Copyright (c) 2019, 2024, Gluon
~ All rights reserved.
~
~ Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -42,12 +42,11 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.resource>21</maven.compiler.resource>
<source.plugin.version>3.3.0</source.plugin.version>
<javadoc.plugin.version>3.5.0</javadoc.plugin.version>
<gpg.plugin.version>3.1.0</gpg.plugin.version>
<maven.resolver.version>1.7.3</maven.resolver.version>
<maven.plugin.version>3.9.9</maven.plugin.version>
<substrate.version>0.0.65-SNAPSHOT</substrate.version>
</properties>

Expand All @@ -60,57 +59,35 @@
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.8.8</version>
<version>${maven.plugin.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.9.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-java</artifactId>
<version>0.9.11</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-exec</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>3.8.8</version>
<version>${maven.plugin.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-invoker</artifactId>
<version>3.2.0</version>
</dependency>

<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-aether-provider</artifactId>
<version>3.3.9</version>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.15.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-transport-http</artifactId>
<version>${maven.resolver.version}</version>
<artifactId>maven-resolver-util</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-transport-file</artifactId>
<version>${maven.resolver.version}</version>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-invoker</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-connector-basic</artifactId>
<version>${maven.resolver.version}</version>
<groupId>org.apache.commons</groupId>
<artifactId>commons-exec</artifactId>
<version>1.4.0</version>
</dependency>
</dependencies>

Expand All @@ -134,12 +111,16 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<version>3.13.0</version>
<configuration>
<source>21</source>
<target>21</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.9.0</version>
<version>3.15.0</version>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
Expand All @@ -155,7 +136,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.4.1</version>
<version>3.5.0</version>
<executions>
<execution>
<id>enforce-no-snapshots</id>
Expand Down
41 changes: 23 additions & 18 deletions src/main/java/com/gluonhq/NativeBaseMojo.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2023, Gluon
* Copyright (c) 2019, 2024, Gluon
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -36,23 +36,24 @@
import com.gluonhq.substrate.SubstrateDispatcher;
import com.gluonhq.substrate.model.Triplet;
import com.gluonhq.substrate.target.WebTargetConfiguration;
import com.gluonhq.substrate.util.Version;
import com.gluonhq.utils.MavenArtifactResolver;
import org.apache.commons.exec.ProcessDestroyer;
import org.apache.commons.exec.ShutdownHookProcessDestroyer;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Repository;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.BuildPluginManager;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.rtinfo.RuntimeInformation;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.artifact.DefaultArtifact;
import org.eclipse.aether.graph.DependencyFilter;
import org.eclipse.aether.repository.RemoteRepository;

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

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

// TODO: Remove this restriction when MavenArtifactResolver works with Maven 3.9.0+
private static final Version MAX_SUPPORTED_MAVEN_VERSION = new Version(3, 8, 8);

Path outputDir;

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

/**
* The entry point to Maven Artifact Resolver
*/
@Component
private RepositorySystem repoSystem;

/**
* The current repository/network configuration of Maven.
*/
@Parameter(defaultValue = "${repositorySystemSession}", readonly = true)
private RepositorySystemSession repoSession;

/**
* The project's remote repositories to use for the resolution.
*/
@Parameter(defaultValue = "${project.remoteProjectRepositories}", readonly = true)
private List<RemoteRepository> remoteRepos;

@Parameter(defaultValue = "${session}", readonly = true)
MavenSession session;

Expand Down Expand Up @@ -157,12 +173,6 @@ public abstract class NativeBaseMojo extends AbstractMojo {
private ProcessDestroyer processDestroyer;

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

private List<File> getClasspathElements(MavenProject project) {
List<Repository> repositories = project.getRepositories();
Repository gluonRepository = new Repository();
gluonRepository.setId("Gluon");
gluonRepository.setUrl("https://nexus.gluonhq.com/nexus/content/repositories/releases");
repositories.add(gluonRepository);
MavenArtifactResolver.initRepositories(repositories);
MavenArtifactResolver.initRepositories(repoSystem, repoSession, remoteRepos);

List<Artifact> attachDependencies = getAttachDependencies();
List<File> list = Stream.concat(project.getArtifacts().stream(), attachDependencies.stream())
Expand Down
Loading

0 comments on commit a1a45a6

Please sign in to comment.