From c4c13ccd193257f2d2c930c4f8439b6ca333c91c Mon Sep 17 00:00:00 2001 From: Slawomir Jaranowski Date: Wed, 13 Jul 2022 00:12:36 +0200 Subject: [PATCH] Get rid of maven-artifact-transfer from dependencies m-artifact-t was only used for dependencies resolving --- pom.xml | 6 --- .../org/codehaus/mojo/exec/ExecJavaMojo.java | 44 +++++++++---------- 2 files changed, 21 insertions(+), 29 deletions(-) diff --git a/pom.xml b/pom.xml index ab55b0f2..a913aeb5 100644 --- a/pom.xml +++ b/pom.xml @@ -155,12 +155,6 @@ commons-exec 1.3 - - - org.apache.maven.shared - maven-artifact-transfer - 0.13.1 - junit diff --git a/src/main/java/org/codehaus/mojo/exec/ExecJavaMojo.java b/src/main/java/org/codehaus/mojo/exec/ExecJavaMojo.java index 6aae6ba8..862eaffb 100644 --- a/src/main/java/org/codehaus/mojo/exec/ExecJavaMojo.java +++ b/src/main/java/org/codehaus/mojo/exec/ExecJavaMojo.java @@ -12,7 +12,6 @@ import java.util.Collection; import java.util.Collections; import java.util.HashSet; -import java.util.LinkedHashSet; import java.util.List; import java.util.Properties; import java.util.Set; @@ -21,19 +20,18 @@ import java.util.concurrent.ForkJoinPool; import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.resolver.ArtifactResolutionException; +import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; +import org.apache.maven.artifact.resolver.ArtifactResolutionResult; +import org.apache.maven.artifact.resolver.ResolutionErrorHandler; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.ResolutionScope; -import org.apache.maven.project.MavenProject; import org.apache.maven.project.ProjectBuilder; -import org.apache.maven.project.ProjectBuildingRequest; -import org.apache.maven.shared.artifact.filter.resolve.AndFilter; -import org.apache.maven.shared.artifact.filter.resolve.TransformableFilter; -import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResult; -import org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolver; +import org.apache.maven.repository.RepositorySystem; /** * Executes the supplied java class in the current VM with the enclosing project's dependencies as classpath. @@ -46,7 +44,10 @@ public class ExecJavaMojo extends AbstractExecMojo { @Component - private DependencyResolver dependencyResolver; + private RepositorySystem repositorySystem; + + @Component + private ResolutionErrorHandler resolutionErrorHandler; /** @@ -702,29 +703,26 @@ private Set determineRelevantPluginDependencies() private Set resolveExecutableDependencies( Artifact executablePomArtifact ) throws MojoExecutionException { - - Set executableDependencies = new LinkedHashSet<>(); try { - ProjectBuildingRequest buildingRequest = getSession().getProjectBuildingRequest(); - - MavenProject executableProject = - this.projectBuilder.build( executablePomArtifact, buildingRequest ).getProject(); + ArtifactResolutionRequest request = new ArtifactResolutionRequest() + .setArtifact( executablePomArtifact ) + .setLocalRepository( getSession().getLocalRepository() ) + .setRemoteRepositories( getSession().getRequest().getRemoteRepositories() ) + .setForceUpdate( getSession().getRequest().isUpdateSnapshots() ) + .setOffline( getSession().isOffline() ) + .setResolveTransitively( true ); - for ( ArtifactResult artifactResult : dependencyResolver.resolveDependencies( buildingRequest, - executableProject.getModel(), - new AndFilter( Collections.emptyList() ) ) ) - { - executableDependencies.add( artifactResult.getArtifact() ); - } + ArtifactResolutionResult result = repositorySystem.resolve( request ); + resolutionErrorHandler.throwErrors( request, result ); + + return result.getArtifacts(); } - catch ( Exception ex ) + catch ( ArtifactResolutionException ex ) { throw new MojoExecutionException( "Encountered problems resolving dependencies of the executable " + "in preparation for its execution.", ex ); } - - return executableDependencies; } /**