'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?



Solution 1:[1]

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

Solution 2:[2]

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.

Solution 3:[3]

As to my knowing, this feature does not yet exist. In the feature request you sent, you can see it's status is still "Unresolved".

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2
Solution 3 carlspring