2
votes

I am using following libraries in my web project:

  • slf4j-log4j12-1.6.4.jar
  • slf4j-api-1.6.0.jar
  • log4j-1.2.16.jar
  • jcl-over-slf4j-1.6.0.jar

Bu when I assembly war an extra commons-logging-1.0.4.jar library is copied to WEB-INF/lib. I think this is because of one of my libraries which depends on commons-logging-1.0.4.jar. I want to exclude commons-logging-1.0.4.jar (due to jcl-over-slf4j-1.6.0.jar is already here) using

<dependency>
    <groupId></groupId>
    <artifactId></artifactId>
    <version></version>
    <exclusions>
           ...
    </exclusions>
</dependency>

For this purpose I need to find what library in my pom depends on commons-logging.

2

2 Answers

6
votes

You can find the dependency tree using mvn dependency:tree command.

From the tree, you can exclude the artifact.

Example output:

[INFO] |  +- org.seleniumhq.selenium:selenium-htmlunit-driver:jar:2.20.0:test
[INFO] |  |  +- org.seleniumhq.selenium:selenium-api:jar:2.20.0:test
[INFO] |  |  +- net.sourceforge.htmlunit:htmlunit:jar:2.9:test
[INFO] |  |  |  +- xalan:xalan:jar:2.7.1:test
[INFO] |  |  |  |  \- xalan:serializer:jar:2.7.1:test
[INFO] |  |  |  +- commons-collections:commons-collections:jar:3.2.1:test
[INFO] |  |  |  +- commons-lang:commons-lang:jar:2.6:test
[INFO] |  |  |  +- org.apache.httpcomponents:httpmime:jar:4.1.2:test
[INFO] |  |  |  +- commons-codec:commons-codec:jar:1.4:test
[INFO] |  |  |  +- net.sourceforge.htmlunit:htmlunit-core-js:jar:2.9:test
[INFO] |  |  |  +- xerces:xercesImpl:jar:2.9.1:test
[INFO] |  |  |  |  \- xml-apis:xml-apis:jar:1.3.04:test

In case the dependency is transitive, you can do as follow based on the above tree:

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-htmlunit-driver</artifactId>
    <version>2.20</version>
</dependency>
<dependency>
    <groupId>net.sourceforge.htmlunit</groupId>
    <artifactId>htmlunit</artifactId>
    <version>2.9</version>
    <!-- i dont want u -->
    <exclusions>
        <exclusion>
            <groupId>commons-collections</groupId>
            <artifactId>commons-collections</artifactId>
        </exclusion>
    </exclusions>
</dependency>
0
votes

If you're using the WAR overlay feature and the other answer with the dependency tree does not work, please check that the library in question does not come in through one of the WAR files that's overlayed. As part of the overlay, Maven is expanding the overlayed WAR file's WEB-INF/lib folder, basically including everything that's in there in your resulting WAR file.

To exclude some of the files coming in this way, you can use the WAR plugin's dependentWarExcludes feature: http://maven.apache.org/plugins/maven-war-plugin/examples/war-overlay.html