Enterprise Java

Maven excludes all transitive dependencies

Transitive dependencies are a new feature in Maven 2.0. This allows you to avoid needing to discover and specify the libraries that your own dependencies require, and including them automatically.”

I had a problem, where some dependencies were available in the run time, but they weren’t available in the public nexus repositories. For an example, Hibernate depends on the Sun JTA API JAR and it is not available in the central Maven repository because it cannot be freely redistributed. So when building the project, it was trying to download transitive dependencies and got failed.

So I looked  a way to ignore all the transitive dependencies, and found that we can ignore all the associated dependencies of a given dependency. There we can exclude all transitive dependencies without specifying groupId and artifactId of the dependencies. So need to use astric(*) character as groupid and artifactid of the dependency.

<dependency>
    <groupId>sample.ProjectA</groupId>
    <artifactId>Project-A</artifactId>
    <version>1.0</version>
    <scope>compile</scope>
    <exclusions>
        <exclusion>
            <groupId>*</groupId>
            <artifactId>*</artifactId>
        </exclusion>
    </exclusions>
</dependency>

This wildcard transitive dependencies ignoring is available with maven 3.2.1 release. So it’s worth to upgrade into latest maven version.

Reference: Maven excludes all transitive dependencies from our JCG partner Chandana Napagoda at the Chandana Napagoda blog blog.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
Back to top button