Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
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+.
–
–
–
–
–
–
Exclusions are still not implemented for dependencyManagement as of current maven 3.6.3. However you can include a project specific "Bill Of Materials" (BOM) as the first dependency in the dependencyManagement section, i.e.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>my-group</groupId>
<artifactId>my-group-project-bom</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
You can then specify all the necessary artifact versions in your project BOM which will take precedence over the spring-boot dependency versions.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.