mirror of https://github.com/apache/maven.git
[MNG-4363] [regression] Dependency artifacts injected by plugins aren't included in class paths
git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@817233 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
fb40b8e83a
commit
08406e1c13
|
@ -142,6 +142,7 @@ public class DefaultProjectDependenciesResolver
|
||||||
for ( MavenProject project : projects )
|
for ( MavenProject project : projects )
|
||||||
{
|
{
|
||||||
request.setArtifact( new ProjectArtifact( project ) );
|
request.setArtifact( new ProjectArtifact( project ) );
|
||||||
|
request.setArtifactDependencies( project.getDependencyArtifacts() );
|
||||||
request.setManagedVersionMap( project.getManagedVersionMap() );
|
request.setManagedVersionMap( project.getManagedVersionMap() );
|
||||||
request.setRemoteRepositories( project.getRemoteArtifactRepositories() );
|
request.setRemoteRepositories( project.getRemoteArtifactRepositories() );
|
||||||
|
|
||||||
|
|
|
@ -309,12 +309,17 @@ public class DefaultLifecycleExecutor
|
||||||
|
|
||||||
for ( MavenProject project : projectsToResolve )
|
for ( MavenProject project : projectsToResolve )
|
||||||
{
|
{
|
||||||
resolveProjectDependencies( project, executionPlan, session, projectBuild.taskSegment.aggregating );
|
resolveProjectDependencies( project, executionPlan.getRequiredCollectionScopes(),
|
||||||
|
executionPlan.getRequiredResolutionScopes(), session,
|
||||||
|
projectBuild.taskSegment.aggregating );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DependencyContext dependencyContext =
|
||||||
|
new DependencyContext( executionPlan, projectBuild.taskSegment.aggregating );
|
||||||
|
|
||||||
for ( MojoExecution mojoExecution : executionPlan.getExecutions() )
|
for ( MojoExecution mojoExecution : executionPlan.getExecutions() )
|
||||||
{
|
{
|
||||||
execute( session, mojoExecution, projectIndex );
|
execute( session, mojoExecution, projectIndex, dependencyContext );
|
||||||
}
|
}
|
||||||
|
|
||||||
long buildEndTime = System.currentTimeMillis();
|
long buildEndTime = System.currentTimeMillis();
|
||||||
|
@ -364,18 +369,15 @@ public class DefaultLifecycleExecutor
|
||||||
fireEvent( session, null, LifecycleEventCatapult.SESSION_ENDED );
|
fireEvent( session, null, LifecycleEventCatapult.SESSION_ENDED );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resolveProjectDependencies( MavenProject project, MavenExecutionPlan executionPlan,
|
private void resolveProjectDependencies( MavenProject project, Collection<String> scopesToCollect,
|
||||||
MavenSession session, boolean aggregating )
|
Collection<String> scopesToResolve, MavenSession session,
|
||||||
|
boolean aggregating )
|
||||||
throws ArtifactResolutionException, ArtifactNotFoundException
|
throws ArtifactResolutionException, ArtifactNotFoundException
|
||||||
{
|
{
|
||||||
Set<Artifact> artifacts;
|
Set<Artifact> artifacts;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Collection<String> scopesToResolve = executionPlan.getRequiredResolutionScopes();
|
|
||||||
|
|
||||||
Collection<String> scopesToCollect = executionPlan.getRequiredCollectionScopes();
|
|
||||||
|
|
||||||
artifacts = projectDependenciesResolver.resolve( project, scopesToCollect, scopesToResolve, session );
|
artifacts = projectDependenciesResolver.resolve( project, scopesToCollect, scopesToResolve, session );
|
||||||
}
|
}
|
||||||
catch ( MultipleArtifactsNotFoundException e )
|
catch ( MultipleArtifactsNotFoundException e )
|
||||||
|
@ -407,6 +409,8 @@ public class DefaultLifecycleExecutor
|
||||||
|
|
||||||
project.setArtifacts( artifacts );
|
project.setArtifacts( artifacts );
|
||||||
|
|
||||||
|
if ( project.getDependencyArtifacts() == null )
|
||||||
|
{
|
||||||
Set<String> directDependencies = new HashSet<String>( project.getDependencies().size() * 2 );
|
Set<String> directDependencies = new HashSet<String>( project.getDependencies().size() * 2 );
|
||||||
for ( Dependency dependency : project.getDependencies() )
|
for ( Dependency dependency : project.getDependencies() )
|
||||||
{
|
{
|
||||||
|
@ -423,6 +427,7 @@ public class DefaultLifecycleExecutor
|
||||||
}
|
}
|
||||||
project.setDependencyArtifacts( dependencyArtifacts );
|
project.setDependencyArtifacts( dependencyArtifacts );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private boolean areAllArtifactsInReactor( Collection<MavenProject> projects, Collection<Artifact> artifacts )
|
private boolean areAllArtifactsInReactor( Collection<MavenProject> projects, Collection<Artifact> artifacts )
|
||||||
{
|
{
|
||||||
|
@ -445,8 +450,72 @@ public class DefaultLifecycleExecutor
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void execute( MavenSession session, MojoExecution mojoExecution, ProjectIndex projectIndex )
|
private class DependencyContext
|
||||||
throws MojoFailureException, MojoExecutionException, PluginConfigurationException, PluginManagerException
|
{
|
||||||
|
|
||||||
|
private final Collection<String> scopesToCollect;
|
||||||
|
|
||||||
|
private final Collection<String> scopesToResolve;
|
||||||
|
|
||||||
|
private final boolean aggregating;
|
||||||
|
|
||||||
|
private MavenProject lastProject;
|
||||||
|
|
||||||
|
private Collection<?> lastDependencyArtifacts;
|
||||||
|
|
||||||
|
private int lastDependencyArtifactCount;
|
||||||
|
|
||||||
|
DependencyContext( Collection<String> scopesToCollect, Collection<String> scopesToResolve, boolean aggregating )
|
||||||
|
{
|
||||||
|
this.scopesToCollect = scopesToCollect;
|
||||||
|
this.scopesToResolve = scopesToResolve;
|
||||||
|
this.aggregating = aggregating;
|
||||||
|
}
|
||||||
|
|
||||||
|
DependencyContext( MavenExecutionPlan executionPlan, boolean aggregating )
|
||||||
|
{
|
||||||
|
this.scopesToCollect = executionPlan.getRequiredCollectionScopes();
|
||||||
|
this.scopesToResolve = executionPlan.getRequiredResolutionScopes();
|
||||||
|
this.aggregating = aggregating;
|
||||||
|
}
|
||||||
|
|
||||||
|
DependencyContext( MojoExecution mojoExecution )
|
||||||
|
{
|
||||||
|
this.scopesToCollect = new TreeSet<String>();
|
||||||
|
this.scopesToResolve = new TreeSet<String>();
|
||||||
|
collectDependencyRequirements( scopesToResolve, scopesToCollect, mojoExecution );
|
||||||
|
this.aggregating = mojoExecution.getMojoDescriptor().isAggregating();
|
||||||
|
}
|
||||||
|
|
||||||
|
public DependencyContext clone()
|
||||||
|
{
|
||||||
|
return new DependencyContext( scopesToCollect, scopesToResolve, aggregating );
|
||||||
|
}
|
||||||
|
|
||||||
|
void checkForUpdate( MavenSession session )
|
||||||
|
throws ArtifactResolutionException, ArtifactNotFoundException
|
||||||
|
{
|
||||||
|
if ( lastProject == session.getCurrentProject() )
|
||||||
|
{
|
||||||
|
if ( lastDependencyArtifacts != lastProject.getDependencyArtifacts()
|
||||||
|
|| ( lastDependencyArtifacts != null && lastDependencyArtifactCount != lastDependencyArtifacts.size() ) )
|
||||||
|
{
|
||||||
|
logger.debug( "Re-resolving dependencies for project " + lastProject.getId()
|
||||||
|
+ " to account for updates by previous goal execution" );
|
||||||
|
resolveProjectDependencies( lastProject, scopesToCollect, scopesToResolve, session, aggregating );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lastProject = session.getCurrentProject();
|
||||||
|
lastDependencyArtifacts = lastProject.getDependencyArtifacts();
|
||||||
|
lastDependencyArtifactCount = ( lastDependencyArtifacts != null ) ? lastDependencyArtifacts.size() : 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void execute( MavenSession session, MojoExecution mojoExecution, ProjectIndex projectIndex,
|
||||||
|
DependencyContext dependencyContext )
|
||||||
|
throws MojoFailureException, MojoExecutionException, PluginConfigurationException, PluginManagerException,
|
||||||
|
ArtifactResolutionException, ArtifactNotFoundException
|
||||||
{
|
{
|
||||||
MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
|
MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
|
||||||
|
|
||||||
|
@ -471,7 +540,10 @@ public class DefaultLifecycleExecutor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<MavenProject> forkedProjects = executeForkedExecutions( mojoExecution, session, projectIndex );
|
dependencyContext.checkForUpdate( session );
|
||||||
|
|
||||||
|
List<MavenProject> forkedProjects =
|
||||||
|
executeForkedExecutions( mojoExecution, session, projectIndex, dependencyContext );
|
||||||
|
|
||||||
fireEvent( session, mojoExecution, LifecycleEventCatapult.MOJO_STARTED );
|
fireEvent( session, mojoExecution, LifecycleEventCatapult.MOJO_STARTED );
|
||||||
|
|
||||||
|
@ -515,14 +587,17 @@ public class DefaultLifecycleExecutor
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<MavenProject> executeForkedExecutions( MojoExecution mojoExecution, MavenSession session )
|
public List<MavenProject> executeForkedExecutions( MojoExecution mojoExecution, MavenSession session )
|
||||||
throws MojoFailureException, MojoExecutionException, PluginConfigurationException, PluginManagerException
|
throws MojoFailureException, MojoExecutionException, PluginConfigurationException, PluginManagerException,
|
||||||
|
ArtifactResolutionException, ArtifactNotFoundException
|
||||||
{
|
{
|
||||||
return executeForkedExecutions( mojoExecution, session, new ProjectIndex( session.getProjects() ) );
|
return executeForkedExecutions( mojoExecution, session, new ProjectIndex( session.getProjects() ),
|
||||||
|
new DependencyContext( mojoExecution ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<MavenProject> executeForkedExecutions( MojoExecution mojoExecution, MavenSession session,
|
private List<MavenProject> executeForkedExecutions( MojoExecution mojoExecution, MavenSession session,
|
||||||
ProjectIndex projectIndex )
|
ProjectIndex projectIndex, DependencyContext dependencyContext )
|
||||||
throws MojoFailureException, MojoExecutionException, PluginConfigurationException, PluginManagerException
|
throws MojoFailureException, MojoExecutionException, PluginConfigurationException, PluginManagerException,
|
||||||
|
ArtifactResolutionException, ArtifactNotFoundException
|
||||||
{
|
{
|
||||||
List<MavenProject> forkedProjects = Collections.emptyList();
|
List<MavenProject> forkedProjects = Collections.emptyList();
|
||||||
|
|
||||||
|
@ -536,6 +611,8 @@ public class DefaultLifecycleExecutor
|
||||||
|
|
||||||
forkedProjects = new ArrayList<MavenProject>( forkedExecutions.size() );
|
forkedProjects = new ArrayList<MavenProject>( forkedExecutions.size() );
|
||||||
|
|
||||||
|
dependencyContext = dependencyContext.clone();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
for ( Map.Entry<String, List<MojoExecution>> fork : forkedExecutions.entrySet() )
|
for ( Map.Entry<String, List<MojoExecution>> fork : forkedExecutions.entrySet() )
|
||||||
|
@ -558,7 +635,7 @@ public class DefaultLifecycleExecutor
|
||||||
|
|
||||||
for ( MojoExecution forkedExecution : fork.getValue() )
|
for ( MojoExecution forkedExecution : fork.getValue() )
|
||||||
{
|
{
|
||||||
execute( session, forkedExecution, projectIndex );
|
execute( session, forkedExecution, projectIndex, dependencyContext );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
|
|
|
@ -22,6 +22,8 @@ package org.apache.maven.lifecycle;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
|
||||||
|
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||||
import org.apache.maven.execution.MavenSession;
|
import org.apache.maven.execution.MavenSession;
|
||||||
import org.apache.maven.model.Plugin;
|
import org.apache.maven.model.Plugin;
|
||||||
import org.apache.maven.plugin.InvalidPluginDescriptorException;
|
import org.apache.maven.plugin.InvalidPluginDescriptorException;
|
||||||
|
@ -107,6 +109,7 @@ public interface LifecycleExecutor
|
||||||
* will never be {@code null}.
|
* will never be {@code null}.
|
||||||
*/
|
*/
|
||||||
List<MavenProject> executeForkedExecutions( MojoExecution mojoExecution, MavenSession session )
|
List<MavenProject> executeForkedExecutions( MojoExecution mojoExecution, MavenSession session )
|
||||||
throws MojoFailureException, MojoExecutionException, PluginConfigurationException, PluginManagerException;
|
throws MojoFailureException, MojoExecutionException, PluginConfigurationException, PluginManagerException,
|
||||||
|
ArtifactResolutionException, ArtifactNotFoundException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue