找出依赖发行者

时间:2012-04-25 07:30:27

标签: java maven dependencies

我在我的网络项目中使用以下库:

  • SLF4J-log4j12-1.6.4.jar
  • SLF4J-API-1.6.0.jar
  • 的log4j-1.2.16.jar
  • JCL-过SLF4J-1.6.0.jar

当我组装战争时,将额外的 commons-logging-1.0.4.jar 库复制到WEB-INF / lib。我认为这是因为我的一个库依赖于commons-logging-1.0.4.jar。 我想排除commons-logging-1.0.4.jar(由于jcl-over-slf4j-1.6.0.jar已经在这里)使用

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

为此,我需要找到我的pom中的库取决于commons-logging。

2 个答案:

答案 0 :(得分:6)

您可以使用mvn dependency:tree命令找到依赖关系树。

从树中,您可以排除工件。

示例输出:

[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

如果依赖项是可传递的,您可以根据上面的树执行以下操作:

<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>

答案 1 :(得分:0)

如果您正在使用 WAR覆盖功能依赖树的其他答案不起作用,请检查相关的库是否未通过其中一个重叠的WAR文件。作为叠加层的一部分,Maven正在扩展重叠的WAR文件的WEB-INF/lib文件夹,基本上包括生成的WAR文件中的所有内容。

要以这种方式排除某些文件,您可以使用WAR插件的dependentWarExcludes功能:http://maven.apache.org/plugins/maven-war-plugin/examples/war-overlay.html