diff --git a/maven-project/src/main/java/org/apache/maven/project/injection/DefaultModelDefaultsInjector.java b/maven-project/src/main/java/org/apache/maven/project/injection/DefaultModelDefaultsInjector.java index 4d0bc4e237..c424ca8d8f 100644 --- a/maven-project/src/main/java/org/apache/maven/project/injection/DefaultModelDefaultsInjector.java +++ b/maven-project/src/main/java/org/apache/maven/project/injection/DefaultModelDefaultsInjector.java @@ -90,6 +90,22 @@ public class DefaultModelDefaultsInjector { dep.setVersion( def.getVersion() ); } + + if ( dep.getClassifier() == null && def.getClassifier() != null ) + { + dep.setClassifier( def.getClassifier() ); + } + + if ( dep.getType() == null && def.getType() != null ) + { + dep.setType( def.getType() ); + } + + List exclusions = dep.getExclusions(); + if ( exclusions == null || exclusions.isEmpty() ) + { + dep.setExclusions( def.getExclusions() ); + } } } \ No newline at end of file diff --git a/maven-project/src/test/java/org/apache/maven/project/injection/DefaultModelDefaultsInjectorTest.java b/maven-project/src/test/java/org/apache/maven/project/injection/DefaultModelDefaultsInjectorTest.java index d655c03268..d0882f1f70 100644 --- a/maven-project/src/test/java/org/apache/maven/project/injection/DefaultModelDefaultsInjectorTest.java +++ b/maven-project/src/test/java/org/apache/maven/project/injection/DefaultModelDefaultsInjectorTest.java @@ -19,8 +19,10 @@ package org.apache.maven.project.injection; import junit.framework.TestCase; import org.apache.maven.model.Dependency; import org.apache.maven.model.DependencyManagement; +import org.apache.maven.model.Exclusion; import org.apache.maven.model.Model; +import java.util.ArrayList; import java.util.List; /** @@ -65,6 +67,51 @@ public class DefaultModelDefaultsInjectorTest assertEquals( def.getVersion(), result.getVersion() ); } + public void testShouldMergeDependencyExclusionsFromDefaultsToDependency() + { + Model model = new Model(); + + Dependency dep = new Dependency(); + dep.setGroupId( "myGroup" ); + dep.setArtifactId( "myArtifact" ); + + model.addDependency( dep ); + + Dependency def = new Dependency(); + def.setGroupId( dep.getGroupId() ); + def.setArtifactId( dep.getArtifactId() ); + def.setVersion( "1.0.1" ); + def.setScope( "scope" ); + + Exclusion exc = new Exclusion(); + exc.setArtifactId( "mydep" ); + exc.setGroupId( "mygrp" ); + + def.addExclusion( exc ); + + DependencyManagement depMgmt = new DependencyManagement(); + + depMgmt.addDependency( def ); + + model.setDependencyManagement( depMgmt ); + + new DefaultModelDefaultsInjector().injectDefaults( model ); + + List deps = model.getDependencies(); + assertEquals( 1, deps.size() ); + + Dependency result = (Dependency) deps.get( 0 ); + assertEquals( def.getVersion(), result.getVersion() ); + + List resultExclusions = result.getExclusions(); + assertNotNull( resultExclusions ); + assertEquals( 1, resultExclusions.size() ); + + Exclusion resultExclusion = (Exclusion) resultExclusions.get( 0 ); + assertEquals( "mydep", resultExclusion.getArtifactId() ); + assertEquals( "mygrp", resultExclusion.getGroupId() ); + } + public void testShouldMergeDefaultUrlAndArtifactWhenDependencyDoesntSupplyVersion() { Model model = new Model();