vendredi 13 mars 2015

Maven Including test Scoped Transitive Dependencies in WAR



Maven 3.0.5 and Maven 3.2.1


I have a Maven project which is a test library aggregation with the intent that if you depend on that project with a scope of "test" that you can have all of the testing libraries you need.


The issue I am having is that a dependency of one of the included testing libraries is getting included in the WAR of the web project.


The test library aggregation project:



<project ...>
<groupId>com.group</groupId>
<artifactId>test-lib</artifactId>
<name>test-lib</name>
<version>1.0.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<version>3.3.1</version>
</dependency>
<dependency>
<groupId>org.apache.directory.server</groupId>
<artifactId>apacheds-test-framework</artifactId>
<version>2.0.0-M19</version>
</dependency>
</dependencies>
</project>


The web project:



<project ...>
<groupId>com.group</groupId>
<artifactId>web-project</artifactId>
<packaging>war</packaging>
<name>web-project</name>
<version>1.0.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.group</groupId>
<artifactId>test-lib</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
</project>


In the web project I am depending on test-lib with a scope of "test". When I look at the dependency hierarchy, all the sub-dependencies of test-lib correctly have a scope of "test".


apacheds-test-framework depends on commons-io 2.4 and commons-fileupload depends on commons-io 1.1.


What I am expecting to happen is that commons-io 2.4 is used only for testing and when the WAR is built, only common-io 1.1 is included in the archive. But what is actually happening is that commons-io 2.4 AND commons-io 1.1 are included in the WAR.


enter image description here


I cannot simply exclude commons-io from test-lib in web-project because test-lib needs 2.4, I cannot upgrade the version of commons-fileupload at this time, and I cannot allow both JARs to be packaged in the WAR.


This seems to be a bug in the way Maven handles trasitive dependencies in some cases. This is not the first time I have had Maven not trasitively test-scope dependencies of test-scoped dependencies. I am at a loss for what to do here.


Thanks in advance.




Aucun commentaire:

Enregistrer un commentaire