添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
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+.

You may need to provide the whole pom.xml, at the least the DependencyManagement and Dependencies sections – alexbt Sep 1, 2016 at 21:15 Also, type this "mvn dependency:tree -Dverbose -Dincludes=com.google.code.gson:gson" to show us where the dependency is really comming from – alexbt Sep 2, 2016 at 1:06 Still not in Maven 3.5.2 Release as on date, this should be in the next maven version as the patch for this: issues.apache.org/jira/browse/MNG-5600 has been pulled into master – Deepak Mar 1, 2018 at 9:16 Some recent activity github.com/apache/maven/pull/295, fingers crossed it will land in Maven 3.7! – levant pied Jan 3, 2020 at 22:32 I am facing the same issue. My maven version is 3.5.2. Just wanted to check is this feature added in maven in their latest version, so that i can exclude the dependency. – Sam Nov 9, 2018 at 5:17 I misunderstood this, so for anyone reading, exclusions do work inside the dependencies declared at dependencyManagement tag, as long as they are not of the <scope>import</scope> (which only works with <type>pom</pom>) – BugsOverflow Apr 24 at 6:12

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.