Search code examples
javamavenmaven-war-plugin

Maven war plugin creates war with multiple versions of same jar


I experience following problem. I've got a legacy application where the maven-war-plugin in following way:

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

Particular situation was that there was a special folder WebRoot on level of src in the source tree of the project

enter image description here

Then when I had changed version of some dependency and started a build with mvn clean package I got in the end a project.war with WEB-INF/lib which was filled with both versions of the artifact new and old one. That makes troubles during the start of the war in servlet container because it's not clear which of the jars gets loaded by classloader and there were different incompability problems with some jars.

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

Solution

  • I found a solution. The problem was really this plugin configuration:

    <configuration>
        <webappDirectory>${basedir}/WebRoot</webappDirectory>
        <warSourceDirectory>${basedir}/WebRoot</warSourceDirectory>
    </configuration>
    

    webappDirectory is by definition the place where maven put exploded war. So after mvn clean package there was a lib folder unter the ${basedir}/WebRoot filled with all the dependency libs from the pom. On the other hand this folder is used for packaging into war. So each time I updated a version of some dependency and started mvn clean package a new version of the dependency got put into ${basedir}/WebRoot/lib without removing the previous version. And after the next mvn clean package it got packaged the whole lib folder into the war.

    The solution is, don't use the same folder for warSourceDirectory and webappDirectory. Point the webappDirectory somewhere into the <webappDirectory>${project.build.directory}/XYZ</webappDirectory>