子pom可以继承父pom中定义的依赖项排除吗? [英] Can child poms inherit dependency exclusions defined in the parent pom?

查看:2976
本文介绍了子pom可以继承父pom中定义的依赖项排除吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定这是否受到Maven的支持.感谢您能提供的任何帮助.

I'm not sure if this is support by Maven or not. I appreciate any help I can get.

我有一个父pom,它定义了一个依赖项和一个排除项.我无法更改父pom:

I have a parent pom that defines a dependency and an exclusion. I can't change the parent 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中,我需要从父对象的相同依赖项中排除不同依赖项.像这样

Then in the child pom, I have a need to exclude a different dependency from that same dependency in the parent. Like so

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

但是,如果我这样做,则该子级将(正确)排除slf4j jar,但不会将其排除在spring-cloud-config-server jar中,除非我在该子级声明中重新声明了父级排除项依赖性.

But if I do that, the child will have the slf4j jar excluded (correctly), but it will NOT have the spring-cloud-config-server jar excluded, unless if I restate the parent exclusion in the child declaration of that dependency.

我意识到我可以复制它,但这很麻烦,而且我意识到将孩子的排斥行为推向父母很容易,但随后我将所有其他孩子都强行排除在外.

I realize I could just copy it, but that's messy, and I realize that it would be easy to push the child's exclusion up to the parent, but then I'd be forcing that exclusion on all the other children.

我想让Maven在父项和子项中声明相同的依赖项时合并依赖项排除信息.

What I'd like is for Maven to merge the dependency exclusion information when the same dependency is declared differently in the parent and child.

有可能吗?

推荐答案

在您的父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>

在您的孩子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>

这篇关于子pom可以继承父pom中定义的依赖项排除吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆