Maven excludes all transitive dependencies

October 08, 2014 ・0comments

Transitive dependencies are a new feature in Maven 2.0. This feature allows you to avoid the need to discover and specify the libraries that your own dependencies require, as they are included automatically.

I encountered a problem where some dependencies were available at runtime, but they weren't available in the public Nexus repositories. For example, Hibernate depends on the Sun JTA API JAR, which is not available in the central Maven repository because it cannot be freely redistributed. Consequently, when building the project, it tried to download transitive dependencies and failed.

To address this issue, I looked for a way to ignore all transitive dependencies and found that we can ignore all 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.

Post a Comment