diff --git a/maven-project/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java b/maven-project/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java index 2dd2a46892..eeb004af69 100644 --- a/maven-project/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java +++ b/maven-project/src/test/java/org/apache/maven/project/DefaultMavenProjectBuilderTest.java @@ -22,6 +22,7 @@ package org.apache.maven.project; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.DefaultArtifactRepository; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; +import org.apache.maven.model.Plugin; import org.codehaus.plexus.util.FileUtils; import java.io.File; @@ -94,6 +95,16 @@ public class DefaultMavenProjectBuilderTest getProject( f2 ); } + public void testDuplicatePluginDefinitionsMerged() + throws Exception + { + File f1 = getTestFile( "src/test/resources/projects/duplicate-plugins-merged-pom.xml" ); + + MavenProject project = getProject( f1 ); + + assertEquals( 2, ( (Plugin) project.getBuildPlugins().get( 0 ) ).getDependencies().size() ); + } + protected ArtifactRepository getLocalRepository() throws Exception { diff --git a/maven-project/src/test/java/org/apache/maven/project/ModelUtilsTest.java b/maven-project/src/test/java/org/apache/maven/project/ModelUtilsTest.java index 8b1d4b4c34..c35246c8ae 100644 --- a/maven-project/src/test/java/org/apache/maven/project/ModelUtilsTest.java +++ b/maven-project/src/test/java/org/apache/maven/project/ModelUtilsTest.java @@ -489,4 +489,29 @@ public class ModelUtilsTest assertEquals( "two", item[1].getValue() ); assertEquals( "three", item[2].getValue() ); } + + public void testShouldMergeTwoPluginDependenciesOnMergeDupePluginDefs() + { + PluginContainer first = new PluginContainer(); + Plugin fPlugin = createPlugin( "g", "a", "1", Collections.EMPTY_MAP ); + Dependency fDep = new Dependency(); + fDep.setGroupId( "group" ); + fDep.setArtifactId( "artifact" ); + fDep.setVersion( "1" ); + + first.addPlugin( fPlugin ); + fPlugin.addDependency( fDep ); + + Plugin sPlugin = createPlugin( "g", "a", "1", Collections.EMPTY_MAP ); + Dependency sDep = new Dependency(); + sDep.setGroupId( "group" ); + sDep.setArtifactId( "artifact2" ); + sDep.setVersion( "1" ); + first.addPlugin( sPlugin ); + sPlugin.addDependency( sDep ); + + ModelUtils.mergeDuplicatePluginDefinitions( first ); + + assertEquals( 2, ((Plugin)first.getPlugins().get( 0 ) ).getDependencies().size() ); + } } diff --git a/maven-project/src/test/resources/projects/duplicate-plugins-merged-pom.xml b/maven-project/src/test/resources/projects/duplicate-plugins-merged-pom.xml new file mode 100644 index 0000000000..9cbbd12df8 --- /dev/null +++ b/maven-project/src/test/resources/projects/duplicate-plugins-merged-pom.xml @@ -0,0 +1,32 @@ + + 4.0.0 + tests.project + duplicate-plugin-defs-merged + 1 + + + + + maven-compiler-plugin + + + group + first + 1 + + + + + maven-compiler-plugin + + + group + second + 1 + + + + + + +