3

How are exclusions in the parent pom affected by exclusions in the child pom? Are the exclusions additive? Here's an example:

....
<dependencyManagement>
  <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>${hibernate.version}</version>
    <exclusions>
      <exclusion>
        <groupId>commons-collections</groupId>
        <artifactId>commons-collections</artifactId>
      </exclusion>
    </exclusions>
  </dependency>    
</dependencyManagement
....

In Child pom -

    .....
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <exclusions>
            <exclusion>
                <groupId>cglib</groupId>
                <artifactId>cglib</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    ....

Ultimately, are both commons-collections and cglib excluded? If so, is there any way I can "bring back" commons-collections for the child project?

Chip
  • 3,226
  • 23
  • 31

1 Answers1

4

Yes, Maven's exclusions are additive. You'll have both exclusions. There is no way to cancel some inherited exclusion other than just re-add it as a new local dependency.

And by the way, it is about 1-2 minutes to verify this at your own computer...

rogerdpack
  • 62,887
  • 36
  • 269
  • 388
Michał Kalinowski
  • 16,925
  • 5
  • 35
  • 48
  • 2
    Thanks for the answer. I verified this, of course :). I wanted to know if this is is documented behavior - because I couldn't find it written anywhere. I would not like for this to suddenly change if a minor maven version changes. Also, "to bring it back" the problem with reusing the dependency is that I have to keep track of the version myself and cannot rely on just changing ${hibernate.version} – Chip May 24 '12 at 11:23
  • OK. I also don't know if it's documented anywhere, but the mechanism behind dependency management is pretty straight and general for any kind of dependency's setup (`scope`, `version` or `exclusions` as well). IMHO you can be sure that it will work this way. – Michał Kalinowski May 24 '12 at 11:41
  • I wonder why `help:effective-pom` doesn't reflect this. I tried with one rule under managed declaration of parent and another rule in unmanaged declaration of child and expected both to show up in the output of effective POM, but it only showed the one in the child. However, `dependency:tree` excluded both, so it is definitely additive. – haridsv Jan 04 '22 at 16:18