diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java index e2ad981e51..cef2b1373d 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java @@ -19,6 +19,8 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -424,8 +426,32 @@ public class DefaultArtifactResolver if ( request.isResolveTransitively() ) { try - { - artifacts = source.retrieve( rootArtifact, localRepository, remoteRepositories ).getArtifacts(); + { + Set directArtifacts = + source.retrieve( rootArtifact, localRepository, remoteRepositories ).getArtifacts(); + + if ( artifacts == null || artifacts.isEmpty() ) + { + artifacts = directArtifacts; + } + else + { + List allArtifacts = new ArrayList(); + allArtifacts.addAll( artifacts ); + allArtifacts.addAll( directArtifacts ); + + Map mergedArtifacts = new LinkedHashMap(); + for ( Artifact artifact : allArtifacts ) + { + String conflictId = artifact.getDependencyConflictId(); + if ( !mergedArtifacts.containsKey( conflictId ) ) + { + mergedArtifacts.put( conflictId, artifact ); + } + } + + artifacts = new LinkedHashSet( mergedArtifacts.values() ); + } } catch ( ArtifactMetadataRetrievalException e ) { diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java index 53e69f3d0b..0544a144ec 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java @@ -468,15 +468,15 @@ public class DefaultLifecycleExecutor throw new LifecycleExecutionException( message ); } - if ( plugin.getVersion() == null ) + for ( Plugin buildPlugin : project.getBuildPlugins() ) { - for ( Plugin buildPlugin : project.getBuildPlugins() ) + if ( buildPlugin.getKey().equals( plugin.getKey() ) ) { - if ( buildPlugin.getKey().equals( plugin.getKey() ) ) + if ( plugin.getVersion() == null || plugin.getVersion().equals( buildPlugin.getVersion() ) ) { plugin = buildPlugin; - break; } + break; } }