Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Maven, how can I exclude all transitive dependencies from a particular dependency?

I want to exclude all transitive dependencies from one dependency. In some places I've seen it suggested to use a wildcard for that

<dependency>
  <groupId>myParentPackage</groupId>
  <artifactId>myParentProject</artifactId>
  <version>1.00.000</version>            
  <exclusions>
    <exclusion>
        <groupId>*</groupId>
        <artifactId>*</artifactId>
    </exclusion>
  </exclusions>
</dependency>

When I do that I get a warning:

'dependencies.dependency.exclusions.exclusion.groupId' for myParentPackage:myParentProject:jar with value '*' does not match a valid id pattern. @ line 146, column 30

The declaration itself is successful though: The transitive dependencies really are ignored in my build.

I've also found a old feature request that does request exactly this feature

So now I don't know if this is a deprecated feature that I shouldn't use, if the warning's wrong, or of the feature hasn't been completely implemented yet (I'm using Maven 3.0.4) ...Does anybody know more about this?

like image 741
Markus Avatar asked May 03 '13 08:05

Markus


People also ask

How do you exclude transitive dependency of transitive dependency?

Multiple transitive dependencies can be excluded by using the <exclusion> tag for each of the dependency you want to exclude and placing all these exclusion tags inside the <exclusions> tag in pom. xml.

How does Maven resolve transitive dependencies?

Transitive Dependencies. Maven avoids the need to discover and specify the libraries that your own dependencies require by including transitive dependencies automatically. This feature is facilitated by reading the project files of your dependencies from the remote repositories specified.

Does Maven provide support to prohibit transitive dependencies?

This rule bans all transitive dependencies. The following parameters are supported by this rule: excludes - specify the dependencies that will be ignored. This can be a list of artifacts in the format groupId[:artifactId[:version[:type[:scope[:classifier]]]]] .


2 Answers

This is a supported feature in Maven 3.2.1 - see 'Transitive dependency excludes' section in the release notes.

like image 137
Lovro Pandžić Avatar answered Oct 15 '22 03:10

Lovro Pandžić


I hate getting Maven warnings myself. I've seen the wildcard approach but have avoided it. Run a mvn dependency:tree goal, discover the top-level dependencies belonging to the artefact in question and exclude each one individually (hopefully the list isn't so vast). This is by far the safest way to approach this problem.

like image 35
2 revs Avatar answered Oct 15 '22 03:10

2 revs