2
votes

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
2
Can you show us your dependencies?Christian
@Christian I added the dependency in the questionrobin
Can you post your full pom?Dave Richardson
Is it possible that you've set the scope after your first maven install? It's possible that maven keeps some dependencies. You should try a Maven-> Update Dependencies and check the "Force updates" box.Christian
I think it is not clear what you want. can you clearify your question?Jens

2 Answers

1
votes

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.

0
votes

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>