diff --git a/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java b/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java index d2e27f96eb..8caf19cd05 100644 --- a/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java +++ b/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java @@ -223,30 +223,40 @@ public class MavenMetadataSource private Artifact createDependencyArtifact( Dependency dependency, Artifact owner, Artifact pom ) throws ArtifactMetadataRetrievalException { - String effectiveScope = getEffectiveScope( dependency.getScope(), ( owner != null ) ? owner.getScope() : null ); - - if ( effectiveScope == null ) - { - return null; - } - - VersionRange versionRange; try { - versionRange = VersionRange.createFromVersionSpec( dependency.getVersion() ); + String inheritedScope = ( owner != null ) ? owner.getScope() : null; + + ArtifactFilter inheritedFilter = ( owner != null ) ? owner.getDependencyFilter() : null; + + return createDependencyArtifact( repositorySystem, dependency, inheritedScope, inheritedFilter ); } catch ( InvalidVersionSpecificationException e ) { throw new ArtifactMetadataRetrievalException( "Invalid version for dependency " + dependency.getManagementKey() + ": " + e.getMessage(), e, pom ); } + } + + private static Artifact createDependencyArtifact( ArtifactFactory factory, Dependency dependency, String inheritedScope, + ArtifactFilter inheritedFilter ) + throws InvalidVersionSpecificationException + { + String effectiveScope = getEffectiveScope( dependency.getScope(), inheritedScope ); + + if ( effectiveScope == null ) + { + return null; + } + + VersionRange versionRange = VersionRange.createFromVersionSpec( dependency.getVersion() ); Artifact dependencyArtifact = - repositorySystem.createDependencyArtifact( dependency.getGroupId(), dependency.getArtifactId(), - versionRange, dependency.getType(), dependency.getClassifier(), - effectiveScope, dependency.isOptional() ); + factory.createDependencyArtifact( dependency.getGroupId(), dependency.getArtifactId(), versionRange, + dependency.getType(), dependency.getClassifier(), effectiveScope, + dependency.isOptional() ); - ArtifactFilter dependencyFilter = ( owner != null ) ? owner.getDependencyFilter() : null; + ArtifactFilter dependencyFilter = inheritedFilter; if ( dependencyFilter != null && !dependencyFilter.include( dependencyArtifact ) ) { @@ -263,7 +273,7 @@ public class MavenMetadataSource return dependencyArtifact; } - private String getEffectiveScope( String originalScope, String inheritedScope ) + private static String getEffectiveScope( String originalScope, String inheritedScope ) { String effectiveScope = Artifact.SCOPE_RUNTIME; @@ -304,7 +314,7 @@ public class MavenMetadataSource return effectiveScope; } - private ArtifactFilter createDependencyFilter( Dependency dependency, ArtifactFilter inheritedFilter ) + private static ArtifactFilter createDependencyFilter( Dependency dependency, ArtifactFilter inheritedFilter ) { ArtifactFilter effectiveFilter = inheritedFilter; @@ -398,19 +408,22 @@ public class MavenMetadataSource @Deprecated public static Set createArtifacts( ArtifactFactory artifactFactory, List dependencies, String inheritedScope, ArtifactFilter dependencyFilter, MavenProject project ) throws InvalidDependencyVersionException - { - return createArtifacts( artifactFactory, dependencies, dependencyFilter ); - } - - private static Set createArtifacts( ArtifactFactory factory, List dependencies, ArtifactFilter filter ) { Set artifacts = new LinkedHashSet(); for ( Dependency d : dependencies ) { - Artifact dependencyArtifact = factory.createArtifact( d.getGroupId(), d.getArtifactId(), d.getVersion(), d.getScope(), d.getType() ); + Artifact dependencyArtifact; + try + { + dependencyArtifact = createDependencyArtifact( artifactFactory, d, inheritedScope, dependencyFilter ); + } + catch ( InvalidVersionSpecificationException e ) + { + throw new InvalidDependencyVersionException( project.getId(), d, project.getFile(), e ); + } - if ( filter.include( dependencyArtifact ) ) + if ( dependencyArtifact != null ) { artifacts.add( dependencyArtifact ); }