Learned the hard way that Maven exclusions do not get inherited from parent pom files if you happen to add an exclusion in a child pom.
An exclusion is a dependency you do not want used when building your project. For instance, if you have a parent project which declares a dependency in it's dependencyManagement section, and that dependency has a transitive dependency that you don't want to be used (i.e. an old version of JAXB) you can exclude the transitive dependency like so:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>some.group</groupId>
<artifactId>some.artifact</artifactId>
<exclusions>
<exclusion>
<groupId>javax.xml</groupId>
<artifactId>jaxb-xjc</artifactId>
</exclusion>
</exclusion>
</dependency>
</dependencies>
</dependencyManagement> |
However, if you have a child project which references the parent containing the exclusion, and the child project itself places another exclusion on the same dependency:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>some.group</groupId>
<artifactId>some.artifact</artifactId>
<exclusions>
<exclusion>
<groupId>javax.xml.parsers</groupId>
<artifactId>jaxp-api</artifactId>
</exclusion>
</exclusion>
</dependency>
</dependencies>
</dependencyManagement> |
It's not like both jaxb-xjc and jaxp-api will be excluded from your build. In fact, when the child specifies its exclusion, that exclusion "wins". It overrides any exclusions specified in the parent's dependencyManagement section.
mvn -X [your goals here] helps a lot when trying to debug which dependencies are actually being used in a build of your code. So for instance: mvn -X clean install will dump out diagnostic info about what JVM you are running, as well as an "mvn dependency:tree" type output of the dependencies being used in your build.
Hope this helps someone else banging their heads against the wall trying to figure out why their exclusions aren't working!