【问题标题】:Import Dependency Management with Exclusion带排除的导入依赖管理
【发布时间】:2017-01-09 14:28:50
【问题描述】:

我有一个漂亮的 BOM,它的 dependencyManagement 部分中有很多依赖项,我想创建另一个 BOM 来导入所有依赖项除了一个。我试过这样做:

... 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>
...

POM 形式上是正确的,并且一切都可以编译。 但排除只是被忽略。我错过了什么?这种方法正确吗?

我正在使用 Maven 3+。

【问题讨论】:

  • 您可能需要提供整个 pom.xml,至少是 DependencyManagement 和 Dependencies 部分
  • 另外,输入这个“mvn dependency:tree -Dverbose -Dincludes=com.google.code.gson:gson”来告诉我们依赖的真正来源
  • Maven 3.4.0 this will be supported 但不幸的是目前没有。
  • 截至日期仍未在 Maven 3.5.2 Release 中,这应该在下一个 maven 版本中作为补丁:issues.apache.org/jira/browse/MNG-5600 已被拉入 master
  • 最近的一些活动github.com/apache/maven/pull/295,祈祷它将登陆 Maven 3.7!

标签: maven


【解决方案1】:

导入时排除不起作用,请尝试将其从依赖项的实际用户中排除

【讨论】:

  • 我也面临同样的问题。我的 Maven 版本是 3.5.2。只是想检查一下这个功能是否在最新版本的 maven 中添加,以便我可以排除依赖项。
【解决方案2】:

从当前的 maven 3.6.3 开始,dependencyManagement 仍然没有实现排除。但是,您可以将项目特定的“材料清单”(BOM)作为依赖项管理部分中的第一个依赖项,即

<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>
            <type>pom</type>
            <version>${spring-boot.version}</version>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

然后,您可以在项目 BOM 中指定所有必要的工件版本,这些版本将优先于 spring-boot 依赖项版本。

【讨论】:

    猜你喜欢
    • 2020-08-11
    • 2013-03-31
    • 2019-09-17
    • 2017-11-28
    • 2012-11-04
    • 1970-01-01
    • 2021-08-25
    • 2021-12-29
    • 1970-01-01
    相关资源
    最近更新 更多