如何找出并排除Maven3的隐式依赖?

时间:2015-10-22 12:09:28

标签: java maven tomcat7 pom.xml dependency-management

我有一个包含多个依赖项的pom.xml文件,其中一个是c3p0-0.9.5.1.jar。但是,在使用Tomcat7部署webapp时,WEB-INF/lib子目录包含相同依赖项的两个版本:

c3p0-0.9.1.1.jar
c3p0-0.9.5.1.jar

我想要排除版本0.9.1.1。我跑:

mvn dependency:tree

但是,只显示版本0.9.5.1,此处未列出其他jar文件。我需要排除该版本,因为它导致库冲突,目前我丑陋的解决方法是通过0.9.1.1手动删除rm版本并重新启动Tomcat7。

我还尝试在每个依赖项上添加<exclude>块,但该文件仍位于Tomcat7 webapp子目录的WEB-INF/lib子目录中。

Maven版本是3.0.5-1。

如何找出生成旧版本的依赖项以及如何强制排除它?

这是完整的pom.xml文件:

<?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>
    <groupId>com.login.cas</groupId>
    <artifactId>local-cas-management</artifactId>
    <packaging>war</packaging>
    <version>4.1.0-SNAPSHOT</version>

    <build>
      <plugins>
        <plugin>
          <artifactId>maven-war-plugin</artifactId>
          <configuration>
            <warName>cas-management</warName>
          </configuration>
        </plugin>
      </plugins>
    </build>

    <dependencies>
        <dependency>
          <groupId>org.jasig.cas</groupId>
          <artifactId>cas-management-webapp</artifactId>
          <version>${cas.version}</version>
          <type>war</type>
          <scope>runtime</scope>
        </dependency>
        <dependency>
          <groupId>org.hibernate</groupId>
          <artifactId>hibernate-core</artifactId>
          <version>${hibernate.version}</version>
          <scope>compile</scope>
        </dependency>
        <dependency>
          <groupId>org.hibernate</groupId>
          <artifactId>hibernate-entitymanager</artifactId>
          <version>${hibernate.version}</version>
        </dependency>
        <dependency>
          <groupId>mysql</groupId>
          <artifactId>mysql-connector-java</artifactId>
          <version>${mysql.connector.version}</version>
        </dependency>
        <dependency>
          <groupId>org.jasig.cas</groupId>
          <artifactId>cas-server-support-jdbc</artifactId>
          <version>${cas.version}</version>
        </dependency>
        <dependency>
          <groupId>org.jasig.cas</groupId>
          <artifactId>cas-server-support-ldap</artifactId>
          <version>${cas.version}</version>
        </dependency>
        <dependency>
          <groupId>xml-apis</groupId>
          <artifactId>xml-apis</artifactId>
          <version>${xml.apis.version}</version>
        </dependency>
       <dependency>
          <groupId>com.mchange</groupId>
          <artifactId>c3p0</artifactId>
          <version>${c3p0.version}</version>
        </dependency>
    </dependencies>

    <properties>
        <commons.dbcp.version>2.0</commons.dbcp.version>
        <cas.version>4.1.1</cas.version>
        <hibernate.version>4.3.10.Final</hibernate.version>
        <mysql.connector.version>5.1.6</mysql.connector.version>
        <xml.apis.version>1.4.01</xml.apis.version>
        <c3p0.version>0.9.5.1</c3p0.version>
    </properties>

    <repositories>
      <repository>
        <id>ja-sig</id>
        <url>http://oss.sonatype.org/content/repositories/releases/ </url>
      </repository>
    </repositories>
</project>

这将是关联的dependency:tree。如您所见,没有版本0.9.1.1

[INFO] com.login.cas:local-cas-management:war:4.1.0-SNAPSHOT
[INFO] +- org.jasig.cas:cas-management-webapp:war:4.1.1:runtime
[INFO] +- org.hibernate:hibernate-core:jar:4.3.10.Final:compile
[INFO] |  +- org.jboss.logging:jboss-logging:jar:3.1.3.GA:compile
[INFO] |  +- org.jboss.logging:jboss-logging-annotations:jar:1.2.0.Beta1:compile
[INFO] |  +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:jar:1.0.0.Final:compile
[INFO] |  +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  +- org.hibernate.common:hibernate-commons-annotations:jar:4.0.5.Final:compile
[INFO] |  +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
[INFO] |  +- org.javassist:javassist:jar:3.18.1-GA:compile
[INFO] |  +- antlr:antlr:jar:2.7.7:compile
[INFO] |  \- org.jboss:jandex:jar:1.1.0.Final:compile
[INFO] +- org.hibernate:hibernate-entitymanager:jar:4.3.10.Final:compile
[INFO] +- mysql:mysql-connector-java:jar:5.1.6:compile
[INFO] +- org.jasig.cas:cas-server-support-jdbc:jar:4.1.1:compile
[INFO] |  +- org.jasig.cas:cas-server-core:jar:4.1.1:compile
[INFO] |  |  +- org.jasig.cas:cas-server-core-api:jar:4.1.1:compile
[INFO] |  |  +- org.jasig.inspektr:inspektr-audit:jar:1.2.GA:compile
[INFO] |  |  |  \- org.jasig.inspektr:inspektr-common:jar:1.2.GA:compile
[INFO] |  |  +- io.dropwizard.metrics:metrics-core:jar:3.1.2:compile
[INFO] |  |  +- io.dropwizard.metrics:metrics-annotation:jar:3.1.2:compile
[INFO] |  |  +- org.jasig.service.persondir:person-directory-impl:jar:1.7.0:compile
[INFO] |  |  |  +- aopalliance:aopalliance:jar:1.0:compile
[INFO] |  |  |  +- com.sun.xml.bind:jaxb-impl:jar:2.2.7:compile
[INFO] |  |  |  |  +- com.sun.xml.bind:jaxb-core:jar:2.2.7:compile
[INFO] |  |  |  |  |  +- javax.xml.bind:jaxb-api:jar:2.2.7:compile
[INFO] |  |  |  |  |  \- com.sun.istack:istack-commons-runtime:jar:2.16:compile
[INFO] |  |  |  |  \- com.sun.xml.fastinfoset:FastInfoset:jar:1.2.12:compile
[INFO] |  |  |  |     \- javax.xml.bind:jsr173_api:jar:1.0:compile
[INFO] |  |  |  \- org.jasig.service.persondir:person-directory-api:jar:1.7.0:compile
[INFO] |  |  +- commons-codec:commons-codec:jar:1.10:compile
[INFO] |  |  +- org.springframework:spring-core:jar:4.1.6.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-beans:jar:4.1.6.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-webmvc:jar:4.1.6.RELEASE:compile
[INFO] |  |  |  \- org.springframework:spring-web:jar:4.1.6.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-context-support:jar:4.1.6.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-tx:jar:4.1.6.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-context:jar:4.1.6.RELEASE:compile
[INFO] |  |  |  \- org.springframework:spring-aop:jar:4.1.6.RELEASE:compile
[INFO] |  |  +- org.springframework.security:spring-security-core:jar:4.0.1.RELEASE:compile
[INFO] |  |  +- commons-jexl:commons-jexl:jar:1.1:runtime
[INFO] |  |  +- commons-io:commons-io:jar:2.4:compile
[INFO] |  |  +- org.reflections:reflections:jar:0.9.10:compile
[INFO] |  |  |  \- com.google.code.findbugs:annotations:jar:2.0.1:compile
[INFO] |  |  +- org.apache.httpcomponents:httpclient:jar:4.4.1:compile
[INFO] |  |  |  +- org.apache.httpcomponents:httpcore:jar:4.4.1:compile
[INFO] |  |  |  \- commons-logging:commons-logging:jar:1.1.3:compile
[INFO] |  |  +- javax.cache:cache-api:jar:1.0.0:compile
[INFO] |  |  +- org.jsr107.ri:cache-ri-impl:jar:1.0.0:runtime
[INFO] |  |  |  \- javax.enterprise:cdi-api:jar:1.0-SP4:runtime
[INFO] |  |  |     +- org.jboss.spec.javax.interceptor:jboss-interceptors-api_1.1_spec:jar:1.0.0.Beta1:runtime
[INFO] |  |  |     +- javax.annotation:jsr250-api:jar:1.0:runtime
[INFO] |  |  |     \- javax.inject:javax.inject:jar:1:runtime
[INFO] |  |  +- com.google.guava:guava:jar:18.0:compile
[INFO] |  |  +- org.bitbucket.b_c:jose4j:jar:0.4.1:compile
[INFO] |  |  \- org.apache.commons:commons-collections4:jar:4.0:compile
[INFO] |  +- org.apache.commons:commons-lang3:jar:3.4:compile
[INFO] |  +- org.springframework:spring-jdbc:jar:4.1.6.RELEASE:compile
[INFO] |  +- org.springframework:spring-orm:jar:4.1.6.RELEASE:compile
[INFO] |  +- org.apache.shiro:shiro-core:jar:1.2.3:compile
[INFO] |  |  \- commons-beanutils:commons-beanutils:jar:1.8.3:compile
[INFO] |  +- org.aspectj:aspectjrt:jar:1.8.6:compile
[INFO] |  +- org.aspectj:aspectjweaver:jar:1.8.6:compile
[INFO] |  +- javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] |  +- org.glassfish.web:javax.el:jar:2.2.6:runtime
[INFO] |  +- org.slf4j:slf4j-api:jar:1.7.12:compile
[INFO] |  +- org.slf4j:jul-to-slf4j:jar:1.7.12:runtime
[INFO] |  +- org.apache.logging.log4j:log4j-api:jar:2.3:runtime
[INFO] |  +- org.apache.logging.log4j:log4j-core:jar:2.3:runtime
[INFO] |  +- org.apache.logging.log4j:log4j-slf4j-impl:jar:2.3:runtime
[INFO] |  +- org.apache.logging.log4j:log4j-jcl:jar:2.3:runtime
[INFO] |  \- org.jasig.inspektr:inspektr-aspects:jar:1.2.GA:compile
[INFO] +- org.jasig.cas:cas-server-support-ldap:jar:4.1.1:compile
[INFO] |  +- org.springframework.webflow:spring-webflow:jar:2.4.1.RELEASE:compile
[INFO] |  |  +- opensymphony:ognl:jar:2.6.11:compile
[INFO] |  |  +- org.springframework.webflow:spring-binding:jar:2.4.1.RELEASE:compile
[INFO] |  |  \- org.springframework.webflow:spring-js:jar:2.4.1.RELEASE:compile
[INFO] |  |     \- org.springframework.webflow:spring-js-resources:jar:2.4.1.RELEASE:compile
[INFO] |  +- org.ldaptive:ldaptive:jar:1.0.7:compile
[INFO] |  +- org.springframework:spring-expression:jar:4.1.6.RELEASE:compile
[INFO] |  +- joda-time:joda-time:jar:2.8.1:compile
[INFO] |  \- com.fasterxml.jackson.core:jackson-databind:jar:2.5.3:compile
[INFO] |     +- com.fasterxml.jackson.core:jackson-annotations:jar:2.5.0:compile
[INFO] |     \- com.fasterxml.jackson.core:jackson-core:jar:2.5.3:compile
[INFO] +- xml-apis:xml-apis:jar:1.4.01:compile
[INFO] \- com.mchange:c3p0:jar:0.9.5.1:compile
[INFO]    \- com.mchange:mchange-commons-java:jar:0.2.10:compile

2 个答案:

答案 0 :(得分:2)

如果您想以干净的方式继续,我强烈建议您使用Eclipse来检查您的依赖关系层次结构。 Maven集成插件为pom.xml文件提供了一个依赖关系层次结构视图,使您可以查看哪些依赖关系相互引用。

在此视图中,您可以通过右键单击并从上下文菜单中选择排除Maven工件... 来手动排除给定工件。

您将看到一个对话框,询问放置依赖项排除的位置。通常你不应该改变选择。点击确定<exclude>元素将自动放入pom.xml文件中。如果您对修改后的pom.xml文件感到满意,请不要在重建项目之前忘记保存它。

除了调整pom.xml文件外,运行mvn clean package命令以确保target文件夹中没有过时的依赖关系。

答案 1 :(得分:1)

试试这个

 <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.6</version>
        <configuration>
          <packagingExcludes>WEB-INF/lib/c3p0-0.9.1.1.jar</packagingExcludes>
        </configuration>
      </plugin>