How to disable transitive dependencies for maven projects?

I came across a JIRA post that contains a solution that includes an exception tag in each POM dependency tag.

But I have many projects, and each project has a huge number of dependency tags. Cannot include this <exclusion>in each of the dependency tags.

Question : Is there a way to globally disable the import of transitive dependencies in maven?

+4
source share
1 answer

In Maven, you cannot disable transitive dependencies for all declared dependencies in one way, as the official documentation indicates

, POM

, , , . , , .


, Maven 3.2.1 , , , .

- pom (!!):

<dependency>
    <groupId>groupId</groupId>
    <artifactId>artifactId</artifactId>
    <version>version</version>
    <exclusions>
        <exclusion>
            <groupId>*</groupId>
            <artifactId>*</artifactId>
        </exclusion>
    </exclusions>
</dependency>

, ( ) , POM , pom :

<parent>
    <groupId>com.sample</groupId>
    <artifactId>projects-governance</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>

POM :

<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.sample</groupId>
    <artifactId>modules</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>

    <dependencyManagement>
        <dependencies>
            <!-- for each and every foreseen dependency of children poms -->
            <dependency>
                <groupId>groupId</groupId>
                <artifactId>artifactId</artifactId>
                <version>version</version>
                <exclusions>
                    <exclusion>
                        <groupId>*</groupId>
                        <artifactId>*</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
        </dependencies>
    </dependencyManagement>
</project>

dependencyManagement, : POM, , , , groupId artifacId , .

, /, POM ( , ).

, POM , , .


, , , ( POM!) :

mvn dependency:list -DexcludeTransitive=true -DoutputFile=dependencies.txt -DappendOutput=true

Maven Dependency Plugin dependencies.txt ( groupId:artifactId:packaging:version:scope) . , appendOutput , ( , pom).


, - ( ) :

    </version>
</dependency>

:

    </version>
    <exclusions>
        <exclusion>
            <groupId>*</groupId>
            <artifactId>*</artifactId>
        </exclusion>
    </exclusions>
</dependency>

. .

OP: , , , / .

+3

All Articles