Skip to content

Commit

Permalink
Get rid of maven-artifact-transfer from dependencies
Browse files Browse the repository at this point in the history
m-artifact-t was only used for dependencies resolving
  • Loading branch information
slawekjaranowski committed Jul 13, 2022
1 parent ba8c068 commit c4c13cc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 29 deletions.
6 changes: 0 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,6 @@
<artifactId>commons-exec</artifactId>
<version>1.3</version>
</dependency>

<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-artifact-transfer</artifactId>
<version>0.13.1</version>
</dependency>

<dependency>
<groupId>junit</groupId>
Expand Down
44 changes: 21 additions & 23 deletions src/main/java/org/codehaus/mojo/exec/ExecJavaMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -46,7 +44,10 @@ public class ExecJavaMojo
extends AbstractExecMojo
{
@Component
private DependencyResolver dependencyResolver;
private RepositorySystem repositorySystem;

@Component
private ResolutionErrorHandler resolutionErrorHandler;


/**
Expand Down Expand Up @@ -702,29 +703,26 @@ private Set<Artifact> determineRelevantPluginDependencies()
private Set<Artifact> resolveExecutableDependencies( Artifact executablePomArtifact )
throws MojoExecutionException
{

Set<Artifact> 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.<TransformableFilter>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;
}

/**
Expand Down

0 comments on commit c4c13cc

Please sign in to comment.