gpt4 book ai didi

maven - 子 pom 可以继承父 pom 中定义的依赖项排除吗?

转载 作者:行者123 更新时间:2023-12-01 01:56:58 28 4
gpt4 key购买 nike

我不确定这是否受 Maven 支持。我很感激我能得到的任何帮助。

我有一个定义依赖项和排除项的父 pom。我无法更改父 pom:

<dependency>
<groupId>foo</groupId>
<artifactId>bar</artifactId>
<version>1.0</version>
<exclusions>
<!-- this exclusion needs to be inherited by all children -->
<exclusion>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</exclusion>
</exclusions>
</dependency>

然后在子 pom 中,我需要从父项中的相同依赖项中排除不同的依赖项。像这样
<dependency>
<groupId>foo</groupId>
<artifactId>bar</artifactId>
<version>1.0</version>
<exclusions>
<!-- this exclusion is just for the child -->
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>

但是如果我这样做, child 将(正确)排除 slf4j jar,但它不会排除 spring-cloud-config-server jar,除非我在该依赖项的子声明中重申父排除。

我意识到我可以直接复制它,但这很麻烦,而且我意识到将 child 的排斥推到 parent 身上很容易,但随后我会将这种排斥强加给所有其他 child 。

我希望 Maven 在父级和子级中以不同方式声明相同的依赖项时合并依赖项排除信息。

那可能吗?

最佳答案

在你的父 pom 中:

<dependencyManagement>
<dependencies>
<dependency>
<groupId>foo</groupId>
<artifactId>bar</artifactId>
<version>1.0</version>
<exclusions>
<!-- this exclusion needs to be inherited by all children -->
<exclusion>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</dependencyManagement>

在您的 child pom 中:
<dependencies>
<dependency>
<groupId>foo</groupId>
<artifactId>bar</artifactId>
<exclusions>
<!-- this exclusion is just for the child -->
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

关于maven - 子 pom 可以继承父 pom 中定义的依赖项排除吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39835372/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com