Maven包括旧版本的依赖项

时间:2014-07-31 09:15:19

标签: java eclipse maven

我正在使用Maven使用以下参数构建WAR文件:mvn clean package

这构建成功但是当我打开WAR时,我看到以下内容:

jackson-core-2.2.3.jar
jackson-core-2.3.0.jar
pushy-0.2.jar
pushy-0.3.jar

这会导致我们的应用程序服务器出现问题(很可能是冲突),我通过手动删除WAR中的旧依赖项来解决这个问题。

我已经检查了Eclipse中的Dependency Hierarchy视图,我没有看到Jackson的2.2.3版本或者Pushy的0.2版本。

我也试过删除我的整个.m2存储库,但这似乎没有任何区别。

为什么Maven会包含这些旧的JAR?

Pom.xml依赖项:

<dependencies>
      <dependency>
        <groupId>core</groupId>
        <artifactId>core</artifactId>
        <version>1.0</version>
      </dependency>
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.31</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.3.0</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>2.3.0</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.3.0</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.16</version>
        </dependency>
        <dependency>
            <groupId>com.threewks.thundr</groupId>
            <artifactId>thundr-mailgun</artifactId>
            <version>1.1.0</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-client</artifactId>
            <version>1.18.1</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-core</artifactId>
            <version>1.18.1</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey.contribs</groupId>
            <artifactId>jersey-multipart</artifactId>
            <version>1.18.1</version>
        </dependency>
    </dependencies>

Core.jar pom.xml depdencies:

<dependencies>
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.3</version>
        </dependency>
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.5</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.3.0</version>
        </dependency>
        <dependency>
            <groupId>org.mariadb.jdbc</groupId>
            <artifactId>mariadb-java-client</artifactId>
            <version>1.1.7</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>1.9.5</version>
        </dependency>
        <dependency>
            <groupId>org.facebook4j</groupId>
            <artifactId>facebook4j-core</artifactId>
            <version>[2.0,)</version>
        </dependency>
        <dependency>
            <groupId>com.relayrides</groupId>
            <artifactId>pushy</artifactId>
            <version>0.3</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.16</version>
        </dependency>
        <dependency>
            <groupId>com.sun.mail</groupId>
            <artifactId>javax.mail</artifactId>
            <version>1.5.2</version>
        </dependency>
        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>javax.mail-api</artifactId>
            <version>1.5.2</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>javax.activation</groupId>
            <artifactId>activation</artifactId>
            <version>1.1.1</version>
        </dependency>
        <dependency>
            <groupId>com.threewks.thundr</groupId>
            <artifactId>thundr-mailgun</artifactId>
            <version>1.1.0</version>
        </dependency>
    </dependencies>

以下是构建WAR时使用mvn运行依赖关系树参数的结果:

  [INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ vimbaserver ---
[INFO] vimbaserver:vimbaserver:war:1.0
[INFO] +- core:core:jar:1.0:compile
[INFO] |  +- (commons-dbcp:commons-dbcp:jar:1.4:compile - omitted for duplicate)
[INFO] |  +- commons-lang:commons-lang:jar:2.3:compile
[INFO] |  +- commons-codec:commons-codec:jar:1.5:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-core:jar:2.3.0:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.3.0:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.3.0:compile
[INFO] |  |  +- (com.fasterxml.jackson.core:jackson-annotations:jar:2.3.0:compile - omitted for duplicate)
[INFO] |  |  \- (com.fasterxml.jackson.core:jackson-core:jar:2.3.0:compile - omitted for duplicate)
[INFO] |  +- org.mariadb.jdbc:mariadb-java-client:jar:1.1.7:compile
[INFO] |  |  +- net.java.dev.jna:jna:jar:3.3.0:compile
[INFO] |  |  \- net.java.dev.jna:jna:jar:platform:3.3.0:compile
[INFO] |  +- junit:junit:jar:4.11:compile
[INFO] |  |  \- org.hamcrest:hamcrest-core:jar:1.3:compile
[INFO] |  +- org.facebook4j:facebook4j-core:jar:2.1.0:compile
[INFO] |  +- com.relayrides:pushy:jar:0.3:compile
[INFO] |  |  +- org.slf4j:slf4j-api:jar:1.7.6:compile
[INFO] |  |  +- io.netty:netty-all:jar:4.0.18.Final:compile
[INFO] |  |  \- com.googlecode.json-simple:json-simple:jar:1.1.1:compile
[INFO] |  |     \- (junit:junit:jar:4.10:compile - omitted for conflict with 4.11)
[INFO] |  +- (log4j:log4j:jar:1.2.16:compile - omitted for duplicate)
[INFO] |  +- com.sun.mail:javax.mail:jar:1.5.2:compile
[INFO] |  |  \- (javax.activation:activation:jar:1.1:compile - omitted for conflict with 1.1.1)
[INFO] |  +- javax.mail:javax.mail-api:jar:1.5.2:runtime
[INFO] |  |  \- (javax.activation:activation:jar:1.1:runtime - omitted for duplicate)
[INFO] |  +- javax.activation:activation:jar:1.1.1:compile
[INFO] |  \- (com.threewks.thundr:thundr-mailgun:jar:1.1.0:compile - omitted for duplicate)
[INFO] +- commons-dbcp:commons-dbcp:jar:1.4:compile
[INFO] |  \- commons-pool:commons-pool:jar:1.5.4:compile
[INFO] +- mysql:mysql-connector-java:jar:5.1.31:compile
[INFO] +- log4j:log4j:jar:1.2.16:compile
[INFO] +- com.threewks.thundr:thundr-mailgun:jar:1.1.0:compile
[INFO] |  \- com.threewks.thundr:thundr-http:jar:1.1.0:compile
[INFO] |     \- com.threewks.thundr:thundr:jar:1.1.0:compile
[INFO] |        +- commons-fileupload:commons-fileupload:jar:1.2.2:compile
[INFO] |        +- joda-time:joda-time:jar:2.3:compile
[INFO] |        +- com.google.code.gson:gson:jar:2.1:compile
[INFO] |        +- com.atomicleopard:expressive:jar:0.9.5:compile
[INFO] |        +- org.jodd:jodd-bean:jar:3.4.4:compile
[INFO] |        |  \- org.jodd:jodd-core:jar:3.4.4:compile
[INFO] |        +- org.jodd:jodd-proxetta:jar:3.4.4:compile
[INFO] |        |  +- (org.slf4j:slf4j-api:jar:1.7.2:compile - omitted for conflict with 1.7.6)
[INFO] |        |  \- (org.jodd:jodd-core:jar:3.4.4:compile - omitted for duplicate)
[INFO] |        +- org.jodd:jodd-servlet:jar:3.4.4:compile
[INFO] |        |  +- (org.jodd:jodd-bean:jar:3.4.4:compile - omitted for duplicate)
[INFO] |        |  +- (org.jodd:jodd-core:jar:3.4.4:compile - omitted for duplicate)
[INFO] |        |  \- org.jodd:jodd-upload:jar:3.4.4:compile
[INFO] |        |     \- (org.jodd:jodd-core:jar:3.4.4:compile - omitted for duplicate)
[INFO] |        +- org.apache.commons:commons-lang3:jar:3.1:compile
[INFO] |        +- javax.inject:javax.inject:jar:1:compile
[INFO] |        \- org.apache.directory.studio:org.apache.commons.codec:jar:1.6:compile
[INFO] |           \- (commons-codec:commons-codec:jar:1.6:compile - omitted for conflict with 1.5)
[INFO] +- com.sun.jersey:jersey-client:jar:1.18.1:compile
[INFO] |  \- (com.sun.jersey:jersey-core:jar:1.18.1:compile - omitted for duplicate)
[INFO] +- com.sun.jersey:jersey-core:jar:1.18.1:compile
[INFO] \- com.sun.jersey.contribs:jersey-multipart:jar:1.18.1:compile
[INFO]    +- org.jvnet.mimepull:mimepull:jar:1.9.3:compile
[INFO]    \- (com.sun.jersey:jersey-core:jar:1.18.1:compile - omitted for duplicate)

2 个答案:

答案 0 :(得分:1)

使用mvn dependency:tree查看传递依赖的位置。排除它们并使用Maven Enforcer plugin来阻止开发人员添加依赖项,从而添加禁止的传递依赖项。

答案 1 :(得分:1)

之前我遇到过这个问题 - 请检查jboss目录中的WEB-INF /文件夹中的旧jar。