In Maven, how can I exclude all transitive depende

2019-02-05 20:32发布

问题:

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?

回答1:

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



回答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.



回答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".