简体   繁体   中英

Issue with Maven war Plugin

I am using maven to package my war file. I have some dependencies with provided as scope. When i do a maven clean install, the war is created successfully, but the transitive dependencies of the jars with scope as provided are included in my lib directory. Is there any way to remove them ?

Example scenario: Below is one of my dependency in pom

    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jaxrs</artifactId>
        <version>${resteasy.version}</version>
        <scope>provided</scope>
    </dependency>

this one is including the jar activation-1.1.jar. Also the dependency tree for resteasy-jaxrs is like below.

[INFO] +- org.jboss.resteasy:resteasy-jaxrs:jar:2.3.6.Final:provided
[INFO] |  +- org.jboss.resteasy:jaxrs-api:jar:2.3.6.Final:provided
[INFO] |  +- javax.annotation:jsr250-api:jar:1.0:compile
[INFO] |  +- javax.activation:activation:jar:1.1:compile
[INFO] |  +- org.apache.httpcomponents:httpclient:jar:4.1.2:provided
[INFO] |  |  \- org.apache.httpcomponents:httpcore:jar:4.1.2:provided
[INFO] |  \- net.jcip:jcip-annotations:jar:1.0:compile

The easiest way is to create a <dependencyManagement> tag and put the sub-dependency inside and set the scope to provided:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>javax.annotation</groupId>
            <artifactId>jsr250-api</artifactId>
            <version>1.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.activation</groupId>
            <artifactId>activation</artifactId>
            <version>1.1</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

That way the scope of your transitive-dependency is overwritten:

[INFO] |  +- javax.annotation:jsr250-api:jar:1.0:provided (scope managed from compile)
[INFO] |  +- javax.activation:activation:jar:1.1:provided (scope managed from compile)

Be sure to do a Maven-> Update Project and check the Force Update checkbox before checking the dependency:tree .

The above mentioned solution is not possible in case i have so many transitive dependencies coming in my lib. Finally got the maven exclusion which is working fine.

<dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-jaxrs</artifactId>
            <version>${resteasy.version}</version>
            <scope>provided</scope>
            <exclusions>
                <exclusion>
                    <artifactId>*</artifactId>
                    <groupId>*</groupId>
                </exclusion>
            </exclusions>
        </dependency>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM