Skip to content

Commit

Permalink
Merge pull request #7 from mojohaus/issue-7
Browse files Browse the repository at this point in the history
BanDuplicateClasses fails the build when two versions of an artifact are in the dependency tree
  • Loading branch information
mfriedenhagen committed Feb 28, 2016
2 parents a02b8a0 + ca14570 commit ba4c415
Show file tree
Hide file tree
Showing 11 changed files with 183 additions and 56 deletions.
21 changes: 21 additions & 0 deletions src/it/issue-7/green-eggs/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.codehaus.mojo.extra-enforcer-rules.it</groupId>
<artifactId>issue-7</artifactId>
<version>0.0.0-SNAPSHOT</version>
</parent>

<artifactId>green-eggs</artifactId>

<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.6</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I would not eat them on a boat.
21 changes: 21 additions & 0 deletions src/it/issue-7/ham/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.codehaus.mojo.extra-enforcer-rules.it</groupId>
<artifactId>issue-7</artifactId>
<version>0.0.0-SNAPSHOT</version>
</parent>

<artifactId>ham</artifactId>

<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.2</version>
</dependency>
</dependencies>

</project>
1 change: 1 addition & 0 deletions src/it/issue-7/ham/src/main/resources/placeholder.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I would not eat them with a goat.
2 changes: 2 additions & 0 deletions src/it/issue-7/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
invoker.goals = package
invoker.buildResult = success
49 changes: 49 additions & 0 deletions src/it/issue-7/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.codehaus.mojo.extra-enforcer-rules.it</groupId>
<artifactId>issue-7</artifactId>
<version>0.0.0-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Multiple versions test</name>

<modules>
<module>green-eggs</module>
<module>ham</module>
<module>sam-i-am</module>
</modules>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>@enforcerPluginVersion@</version>
<dependencies>
<dependency>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>enforce-rules</id>
<phase>validate</phase>
<goals>
<goal>enforce</goal>
</goals>
</execution>
</executions>
<configuration>
<rules>
<banDuplicateClasses/>
</rules>
</configuration>
</plugin>
</plugins>
</build>

</project>
26 changes: 26 additions & 0 deletions src/it/issue-7/sam-i-am/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.codehaus.mojo.extra-enforcer-rules.it</groupId>
<artifactId>issue-7</artifactId>
<version>0.0.0-SNAPSHOT</version>
</parent>

<artifactId>sam-i-am</artifactId>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>green-eggs</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>ham</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

</project>
1 change: 1 addition & 0 deletions src/it/issue-7/sam-i-am/src/main/resources/placeholder.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I do not like green eggs and ham!
2 changes: 1 addition & 1 deletion src/it/mojo-1682/invoker.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
invoker.goals = enforcer:enforce
invoker.goals = enforcer:enforce
invoker.buildResult = failure
92 changes: 47 additions & 45 deletions src/it/mojo-1682/pom.xml
Original file line number Diff line number Diff line change
@@ -1,45 +1,47 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.codehaus.mojo.extra-enforcer-rules.it</groupId>
<artifactId>mojo-1682</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Transitive test</name>

<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>2.5.6</version>
</dependency>
<dependency>
<groupId>springframework</groupId>
<artifactId>spring-core</artifactId>
<version>1.2.6</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>@enforcerPluginVersion@</version>
<dependencies>
<dependency>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
</dependency>
</dependencies>
<configuration>
<rules>
<banDuplicateClasses/>
</rules>
</configuration>
</plugin>
</plugins>
</build>

</project>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.codehaus.mojo.extra-enforcer-rules.it</groupId>
<artifactId>mojo-1682</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Transitive test</name>

<dependencies>
<!-- Depends on 'org.apache.tomcat:tomcat-annotations-api' which bundles some javax.servlet classes -->
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-catalina</artifactId>
<version>7.0.61</version>
</dependency>
<!-- Depends on 'org.jboss.spec.javax.servlet:jboss-servlet-api_3.0_spec' which contains javax.servlet classes -->
<dependency>
<groupId>org.jboss.spec.javax.security.jacc</groupId>
<artifactId>jboss-jacc-api_1.4_spec</artifactId>
<version>1.0.3.Final</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>@enforcerPluginVersion@</version>
<dependencies>
<dependency>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
</dependency>
</dependencies>
<configuration>
<rules>
<banDuplicateClasses/>
</rules>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,20 @@ private Set<Artifact> getAllDescendants( DependencyNode node )
{
try
{
Artifact artifact = depNode.getArtifact();

resolver.resolve( artifact, remoteRepositories, localRepository );

children.add( artifact );

Set<Artifact> subNodes = getAllDescendants( depNode );

if( subNodes != null )
if ( depNode.getState() == DependencyNode.INCLUDED )
{
children.addAll(subNodes);
Artifact artifact = depNode.getArtifact();

resolver.resolve( artifact, remoteRepositories, localRepository );

children.add( artifact );

Set<Artifact> subNodes = getAllDescendants( depNode );

if( subNodes != null )
{
children.addAll(subNodes);
}
}
}
catch ( ArtifactResolutionException e )
Expand Down

0 comments on commit ba4c415

Please sign in to comment.