Search code examples
maven

Import Dependency Management with Exclusion


I have a beautiful BOM with a lot of dependencies in its dependencyManagement section and I would like to create another BOM that imports all that dependencies except one. I tried doing this:

... in my dependencyManagement section
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-dependencies</artifactId>
    <version>${spring-boot-version}</version>
    <type>pom</type>
    <scope>import</scope>

    <exclusions>
        <exclusion>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        </exclusion>
    </exclusions>
</dependency>
...

The POM is formally correct and everything compiles. But the exclusion is simply ignored. What am I missing? Is this approach correct?

I'm using Maven 3+.


Solution

  • Exclusion at import won't work, try excluding it from the actual user of the dependency