Maven war插件使用相同jar的多个版本创建战争

时间:2018-01-11 16:06:45

标签: java maven maven-war-plugin

我遇到以下问题。我有一个遗留应用程序,其中maven-war-plugin以下列方式:

<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
        <webappDirectory>${basedir}/WebRoot</webappDirectory>
        <warSourceDirectory>${basedir}/WebRoot</warSourceDirectory>
    </configuration>
    <version>3.2.0</version>
</plugin>

特殊情况是项目源代码树中的src级别有一个特殊的文件夹WebRoot

enter image description here

然后,当我更改了某些依赖项的版本并开始构建时 mvn clean package我最终得到了一个带有WEB-INF/lib的project.war,其中充满了新旧工具的两个版本。这在servlet容器的战争开始时会产生麻烦,因为不清楚哪个罐子被类加载器加载,并且某些罐子存在不同的不兼容性问题。

编辑: mvn dependency:tree -Dverbose

[INFO] yyy:sometool:war:0.1.15-SNAPSHOT
[INFO] +- org.slf4j:slf4j-api:jar:1.6.4:compile
[INFO] +- ch.qos.logback:logback-classic:jar:1.0.1:compile
[INFO] |  +- ch.qos.logback:logback-core:jar:1.0.1:compile
[INFO] |  \- (org.slf4j:slf4j-api:jar:1.6.4:compile - omitted for duplicate)
[INFO] +- org.slf4j:log4j-over-slf4j:jar:1.6.4:compile
[INFO] |  \- (org.slf4j:slf4j-api:jar:1.6.4:compile - omitted for duplicate)
[INFO] +- org.slf4j:jcl-over-slf4j:jar:1.6.4:compile
[INFO] |  \- (org.slf4j:slf4j-api:jar:1.6.4:compile - omitted for duplicate)
[INFO] +- javax.mail:mail:jar:1.4.1:compile
[INFO] |  \- javax.activation:activation:jar:1.1:compile
[INFO] +- javax.servlet:jstl:jar:1.2:provided
[INFO] +- javax.servlet:servlet-api:jar:2.4:provided
[INFO] +- javax.servlet.jsp:jsp-api:jar:2.1:provided
[INFO] +- org.codehaus.woodstox:wstx-lgpl:jar:3.2.7:compile
[INFO] |  \- stax:stax-api:jar:1.0.1:compile
[INFO] +- org.apache.struts:struts2-core:jar:2.1.8:compile
[INFO] |  +- com.opensymphony:xwork-core:jar:2.1.6:compile
[INFO] |  |  +- org.springframework:spring-test:jar:2.5.6:compile
[INFO] |  |  |  +- (commons-logging:commons-logging:jar:1.1.1:compile - omitted for conflict with 1.0.4)
[INFO] |  |  |  \- (junit:junit:jar:3.8.1:compile - omitted for conflict with 3.8.2)
[INFO] |  |  \- (ognl:ognl:jar:2.7.3:compile - omitted for duplicate)
[INFO] |  +- org.freemarker:freemarker:jar:2.3.15:compile
[INFO] |  +- ognl:ognl:jar:2.7.3:compile
[INFO] |  +- commons-fileupload:commons-fileupload:jar:1.2.1:compile
[INFO] |  \- commons-io:commons-io:jar:1.3.2:compile
[INFO] +- org.apache.struts:struts2-convention-plugin:jar:2.1.8:compile
[INFO] |  \- (org.apache.struts:struts2-core:jar:2.1.8:compile - omitted for duplicate)
[INFO] +- org.apache.struts:struts2-dojo-plugin:jar:2.1.8:compile
[INFO] |  \- (org.apache.struts:struts2-core:jar:2.1.8:compile - omitted for duplicate)
[INFO] +- struts2plugin:struts2pluginLogin:jar:0.0.6:compile
[INFO] |  +- (org.slf4j:slf4j-api:jar:1.6.4:compile - omitted for duplicate)
[INFO] |  \- (ch.qos.logback:logback-classic:jar:1.0.0:compile - omitted for conflict with 1.0.1)
[INFO] +- org.apache.struts:struts2-json-plugin:jar:2.1.8:compile
[INFO] |  +- org.apache.struts:struts2-junit-plugin:jar:2.1.8:compile
[INFO] |  |  +- (junit:junit:jar:3.8.2:compile - omitted for conflict with 4.8.1)
[INFO] |  |  \- (org.apache.struts:struts2-core:jar:2.1.8:compile - omitted for duplicate)
[INFO] |  \- (org.apache.struts:struts2-core:jar:2.1.8:compile - omitted for duplicate)
[INFO] +- org.hibernate:hibernate-annotations:jar:3.3.1.GA:compile
[INFO] |  +- (org.hibernate:hibernate:jar:3.2.6.ga:compile - omitted for conflict with 3.2.5.ga)
[INFO] |  +- org.hibernate:hibernate-commons-annotations:jar:3.0.0.ga:compile
[INFO] |  |  \- (commons-logging:commons-logging:jar:1.0.4:compile - omitted for duplicate)
[INFO] |  +- org.hibernate:ejb3-persistence:jar:1.0.1.GA:compile
[INFO] |  \- commons-logging:commons-logging:jar:1.0.4:compile
[INFO] +- org.hibernate:hibernate-entitymanager:jar:3.3.2.GA:compile
[INFO] |  +- (org.hibernate:hibernate:jar:3.2.6.ga:compile - omitted for duplicate)
[INFO] |  +- (org.hibernate:hibernate-annotations:jar:3.3.1.GA:compile - omitted for duplicate)
[INFO] |  +- (org.hibernate:hibernate-commons-annotations:jar:3.0.0.ga:compile - omitted for duplicate)
[INFO] |  +- (org.hibernate:ejb3-persistence:jar:1.0.1.GA:compile - omitted for duplicate)
[INFO] |  +- (commons-logging:commons-logging:jar:1.0.4:compile - omitted for duplicate)
[INFO] |  \- javassist:javassist:jar:3.4.GA:compile
[INFO] +- org.hibernate:hibernate-validator:jar:3.0.0.ga:compile
[INFO] +- org.hibernate:hibernate:jar:3.2.5.ga:compile
[INFO] |  +- net.sf.ehcache:ehcache:jar:1.2.3:compile
[INFO] |  |  +- (commons-logging:commons-logging:jar:1.0.4:compile - omitted for duplicate)
[INFO] |  |  \- (commons-collections:commons-collections:jar:2.1:compile - omitted for conflict with 2.1.1)
[INFO] |  +- (javax.transaction:jta:jar:1.0.1B:compile - omitted for conflict with 1.1)
[INFO] |  +- (commons-logging:commons-logging:jar:1.0.4:compile - omitted for duplicate)
[INFO] |  +- asm:asm-attrs:jar:1.5.3:compile
[INFO] |  +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  +- antlr:antlr:jar:2.7.6:compile
[INFO] |  +- cglib:cglib:jar:2.1_3:compile
[INFO] |  |  \- (asm:asm:jar:1.5.3:compile - omitted for duplicate)
[INFO] |  +- asm:asm:jar:1.5.3:compile
[INFO] |  \- (commons-collections:commons-collections:jar:2.1.1:compile - omitted for conflict with 3.2.1)
[INFO] +- mysql:mysql-connector-java:jar:5.1.13:compile
[INFO] +- c3p0:c3p0:jar:0.9.1.2:compile
[INFO] +- xerces:xercesImpl:jar:2.9.1:compile
[INFO] |  \- (xml-apis:xml-apis:jar:1.3.04:compile - omitted for conflict with 1.0.b2)
[INFO] +- displaytag:displaytag:jar:1.2:compile
[INFO] |  +- (commons-collections:commons-collections:jar:3.1:compile - omitted for conflict with 2.1.1)
[INFO] |  +- commons-lang:commons-lang:jar:2.3:compile
[INFO] |  +- com.lowagie:itext:jar:1.3:compile
[INFO] |  \- commons-beanutils:commons-beanutils:jar:1.7.0:compile
[INFO] +- javax.transaction:jta:jar:1.1:compile
[INFO] +- javax.persistence:persistence-api:jar:1.0:compile
[INFO] +- org.quartz-scheduler:quartz:jar:2.1.5:compile
[INFO] |  +- (c3p0:c3p0:jar:0.9.1.1:compile - omitted for conflict with 0.9.1.2)
[INFO] |  \- (org.slf4j:slf4j-api:jar:1.6.1:compile - omitted for conflict with 1.6.4)
[INFO] +- org.springframework:spring-context:jar:5.0.2.RELEASE:compile
[INFO] |  +- org.springframework:spring-aop:jar:5.0.2.RELEASE:compile
[INFO] |  |  +- (org.springframework:spring-beans:jar:5.0.2.RELEASE:compile - omitted for duplicate)
[INFO] |  |  \- (org.springframework:spring-core:jar:5.0.2.RELEASE:compile - omitted for duplicate)
[INFO] |  +- org.springframework:spring-beans:jar:5.0.2.RELEASE:compile
[INFO] |  |  \- (org.springframework:spring-core:jar:5.0.2.RELEASE:compile - omitted for duplicate)
[INFO] |  +- org.springframework:spring-core:jar:5.0.2.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-jcl:jar:5.0.2.RELEASE:compile
[INFO] |  \- org.springframework:spring-expression:jar:5.0.2.RELEASE:compile
[INFO] |     \- (org.springframework:spring-core:jar:5.0.2.RELEASE:compile - omitted for duplicate)
[INFO] +- org.springframework:spring-webmvc:jar:5.0.2.RELEASE:compile
[INFO] |  +- (org.springframework:spring-aop:jar:5.0.2.RELEASE:compile - omitted for duplicate)
[INFO] |  +- (org.springframework:spring-beans:jar:5.0.2.RELEASE:compile - omitted for duplicate)
[INFO] |  +- (org.springframework:spring-context:jar:5.0.2.RELEASE:compile - omitted for duplicate)
[INFO] |  +- (org.springframework:spring-core:jar:5.0.2.RELEASE:compile - omitted for duplicate)
[INFO] |  +- (org.springframework:spring-expression:jar:5.0.2.RELEASE:compile - omitted for duplicate)
[INFO] |  \- org.springframework:spring-web:jar:5.0.2.RELEASE:compile
[INFO] |     +- (org.springframework:spring-beans:jar:5.0.2.RELEASE:compile - omitted for duplicate)
[INFO] |     \- (org.springframework:spring-core:jar:5.0.2.RELEASE:compile - omitted for duplicate)
[INFO] +- commons-collections:commons-collections:jar:3.2.1:compile
[INFO] +- net.unto.twitter:java-twitter:jar:0.9-SNAPSHOT:compile
[INFO] |  +- commons-httpclient:commons-httpclient:jar:3.1:compile
[INFO] |  |  +- (commons-logging:commons-logging:jar:1.0.4:compile - omitted for duplicate)
[INFO] |  |  \- commons-codec:commons-codec:jar:1.2:compile
[INFO] |  +- (commons-io:commons-io:jar:1.4:compile - omitted for conflict with 1.3.2)
[INFO] |  +- com.google.protobuf:protobuf-java:jar:2.2.0:compile
[INFO] |  +- (commons-lang:commons-lang:jar:2.4:compile - omitted for conflict with 2.3)
[INFO] |  +- net.sf.json-lib:json-lib:jar:jdk15:2.2.3:compile
[INFO] |  |  +- (commons-beanutils:commons-beanutils:jar:1.7.0:compile - omitted for duplicate)
[INFO] |  |  +- (commons-collections:commons-collections:jar:3.2:compile - omitted for conflict with 3.2.1)
[INFO] |  |  +- (commons-lang:commons-lang:jar:2.4:compile - omitted for conflict with 2.3)
[INFO] |  |  +- (commons-logging:commons-logging:jar:1.1.1:compile - omitted for conflict with 1.0.4)
[INFO] |  |  \- net.sf.ezmorph:ezmorph:jar:1.0.6:compile
[INFO] |  |     \- (commons-lang:commons-lang:jar:2.3:compile - omitted for duplicate)
[INFO] |  +- (joda-time:joda-time:jar:1.6:compile - omitted for conflict with 2.9.9)
[INFO] |  \- com.google.collections:google-collections:jar:0.9:compile
[INFO] +- junit:junit:jar:4.8.1:test (scope not updated to compile)
[INFO] +- xml-apis:xml-apis:jar:1.0.b2:compile
[INFO] +- joda-time:joda-time:jar:2.9.9:compile
[INFO] +- com.google.guava:guava:jar:19.0:compile
[INFO] +- utils.networking:httpclient:jar:0.1.4:compile
[INFO] |  +- (junit:junit:jar:4.10:compile - omitted for conflict with 4.8.1)
[INFO] |  +- (org.slf4j:slf4j-api:jar:1.6.4:compile - omitted for duplicate)
[INFO] |  +- (org.slf4j:log4j-over-slf4j:jar:1.6.4:compile - omitted for duplicate)
[INFO] |  +- (org.slf4j:jcl-over-slf4j:jar:1.6.4:compile - omitted for duplicate)
[INFO] |  +- org.apache.httpcomponents:httpclient:jar:4.1.3:compile
[INFO] |  |  +- org.apache.httpcomponents:httpcore:jar:4.1.4:compile
[INFO] |  |  +- (commons-logging:commons-logging:jar:1.1.1:compile - omitted for conflict with 1.0.4)
[INFO] |  |  \- (commons-codec:commons-codec:jar:1.4:compile - omitted for conflict with 1.2)
[INFO] |  +- (org.springframework:spring-core:jar:3.1.1.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] |  +- (org.springframework:spring-context:jar:3.1.1.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] |  +- (org.springframework:spring-beans:jar:3.1.1.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] |  +- org.springframework.security:spring-security-core:jar:3.1.0.RELEASE:compile
[INFO] |  |  +- aopalliance:aopalliance:jar:1.0:compile
[INFO] |  |  +- (org.springframework:spring-expression:jar:3.0.6.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] |  |  +- (org.springframework:spring-aop:jar:3.0.6.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] |  |  +- (org.springframework:spring-context:jar:3.0.6.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] |  |  +- (org.springframework:spring-beans:jar:3.0.6.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] |  |  +- (org.springframework:spring-core:jar:3.0.6.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] |  |  \- org.springframework.security:spring-security-crypto:jar:3.1.0.RELEASE:compile
[INFO] |  |     \- (org.springframework:spring-core:jar:3.0.6.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] |  +- org.springframework.security:spring-security-web:jar:3.1.0.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-tx:jar:3.0.6.RELEASE:compile
[INFO] |  |  |  +- (aopalliance:aopalliance:jar:1.0:compile - omitted for duplicate)
[INFO] |  |  |  +- (org.springframework:spring-aop:jar:3.0.6.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] |  |  |  +- (org.springframework:spring-beans:jar:3.0.6.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] |  |  |  +- (org.springframework:spring-context:jar:3.0.6.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] |  |  |  \- (org.springframework:spring-core:jar:3.0.6.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] |  |  +- (org.springframework:spring-web:jar:3.0.6.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] |  |  +- (aopalliance:aopalliance:jar:1.0:compile - omitted for duplicate)
[INFO] |  |  +- (org.springframework:spring-expression:jar:3.0.6.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] |  |  +- (org.springframework:spring-aop:jar:3.0.6.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] |  |  +- (org.springframework.security:spring-security-core:jar:3.1.0.RELEASE:compile - omitted for duplicate)
[INFO] |  |  +- org.springframework:spring-jdbc:jar:3.0.6.RELEASE:compile
[INFO] |  |  |  +- (org.springframework:spring-beans:jar:3.0.6.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] |  |  |  +- (org.springframework:spring-core:jar:3.0.6.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] |  |  |  \- (org.springframework:spring-tx:jar:3.0.6.RELEASE:compile - omitted for duplicate)
[INFO] |  |  +- (org.springframework:spring-context:jar:3.0.6.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] |  |  +- (org.springframework:spring-beans:jar:3.0.6.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] |  |  \- (org.springframework:spring-core:jar:3.0.6.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] |  \- org.springframework.security:spring-security-config:jar:3.1.0.RELEASE:compile
[INFO] |     +- (org.springframework:spring-context:jar:3.0.6.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] |     +- (org.springframework:spring-beans:jar:3.0.6.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] |     +- (aopalliance:aopalliance:jar:1.0:compile - omitted for duplicate)
[INFO] |     +- (org.springframework:spring-aop:jar:3.0.6.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] |     +- (org.springframework.security:spring-security-core:jar:3.1.0.RELEASE:compile - omitted for duplicate)
[INFO] |     \- (org.springframework:spring-core:jar:3.0.6.RELEASE:compile - omitted for conflict with 5.0.2.RELEASE)
[INFO] +- com.fasterxml.jackson.core:jackson-core:jar:2.9.3:compile
[INFO] +- com.fasterxml.jackson.core:jackson-databind:jar:2.9.3:compile
[INFO] |  +- (com.fasterxml.jackson.core:jackson-annotations:jar:2.9.0:compile - omitted for conflict with 2.9.3)
[INFO] |  \- (com.fasterxml.jackson.core:jackson-core:jar:2.9.3:compile - omitted for duplicate)
[INFO] +- com.fasterxml.jackson.core:jackson-annotations:jar:2.9.3:compile
[INFO] \- org.mockito:mockito-core:jar:1.9.0:compile
[INFO]    +- org.hamcrest:hamcrest-core:jar:1.1:compile
[INFO]    \- org.objenesis:objenesis:jar:1.0:compile

1 个答案:

答案 0 :(得分:0)

我找到了解决方案。问题实际上是这个插件配置:

<configuration>
    <webappDirectory>${basedir}/WebRoot</webappDirectory>
    <warSourceDirectory>${basedir}/WebRoot</warSourceDirectory>
</configuration>
根据定义,

webappDirectory是maven爆炸战争的地方。所以在mvn clean package之后有一个lib文件夹,${basedir}/WebRoot填充了来自pom的所有依赖库。另一方面,该文件夹用于包装成战争。因此,每次我更新某个依赖项的版本并启动mvn clean package时,都会将新版本的依赖项放入${basedir}/WebRoot/lib而不删除以前的版本。在下一个mvn clean package之后,它将整个lib文件夹打包到战争中。

解决方案是,不要为warSourceDirectorywebappDirectory使用相同的文件夹。将webappDirectory指向某处<webappDirectory>${project.build.directory}/XYZ</webappDirectory>

相关问题