如何从Maven组中排除所有工件? [英] how to exclude all artifacts from a group in maven?

查看:65
本文介绍了如何从Maven组中排除所有工件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Maven 3与Enforcer插件配置为强制版本收敛.我正在使用Spring 3.1.2和Spring Security 3.1.3.

I am using maven 3 with the Enforcer plugin configured to force version convergence. I am using Spring 3.1.2 and Spring Security 3.1.3.

问题在于Spring 3.1.3 POM声明了对Spring 3.0.7的依赖关系,因为这是Spring安全性的最低版本.这意味着强制插件会抱怨,因为传递依赖图同时具有Spring 3.1.2和Spring 3.0.7.

The problem is that Spring 3.1.3 POM declares dependencies on Spring 3.0.7 because that is the minimum version need for spring security. This means that the enforcer plugin complains because the transitive dependency graph has both Spring 3.1.2 and Spring 3.0.7 in it.

修复程序是明确将spring 3.0.7排除为spring安全性的依赖项,以便使执行器插件感到满意.

The fix is to explicitly exclude spring 3.0.7 as a dependency of spring security so that the enforcer plugin in happy.

下面的代码段就是这样做的,问题是我必须为每个弹簧安全罐重复重复相同的代码段,这很繁琐,并且使pom难以阅读,是否存在告诉行家一些事情的方法.

The code snippet below does just that, the problem with it is that I am having to repeat the same snippet over and over gain for each jar of spring security, this is tedious and makes the pom hard to read, is there a way to tell maven something along the lines.

对于org.springframework.security的依赖关系,无论什么artificatId忽略了安全框架对spring框架的依赖关系?

for the dependency org.springframework.security no matter what artificatId ignore the dependency of the security framework on the spring framework?

<dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-acl</artifactId>
            <version>${spring.security.version}</version>
            <exclusions>
                <exclusion>
                    <artifactId>spring-tx</artifactId>
                    <groupId>org.springframework</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>spring-asm</artifactId>
                    <groupId>org.springframework</groupId>
                </exclusion>

                <exclusion>
                    <artifactId>spring-core</artifactId>
                    <groupId>org.springframework</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>spring-aop</artifactId>
                    <groupId>org.springframework</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>spring-beans</artifactId>
                    <groupId>org.springframework</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>spring-jdbc</artifactId>
                    <groupId>org.springframework</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>spring-expression</artifactId>
                    <groupId>org.springframework</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>spring-context</artifactId>
                    <groupId>org.springframework</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>${spring.security.version}</version>
            <exclusions>
                <exclusion>
                    <artifactId>spring-aop</artifactId>
                    <groupId>org.springframework</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>spring-core</artifactId>
                    <groupId>org.springframework</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>spring-expression</artifactId>
                    <groupId>org.springframework</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>spring-beans</artifactId>
                    <groupId>org.springframework</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>spring-context</artifactId>
                    <groupId>org.springframework</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>aopalliance</artifactId>
                    <groupId>aopalliance</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>spring-web</artifactId>
                    <groupId>org.springframework</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>spring-jdbc</artifactId>
                    <groupId>org.springframework</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>spring-tx</artifactId>
                    <groupId>org.springframework</groupId>
                </exclusion>
            </exclusions>
        </dependency>

推荐答案

这可能对您没有太大帮助,但是有一个功能要求,允许排除使用通配符,但是当前版本的Maven中没有此功能( 3.0.4). (Maven 3.2.1中现已提供此功能)

This probably won't help you much, but there is a feature request to allow wildcards in exclusions, however it is not in the current release version of Maven (3.0.4). ( this feature is now present in Maven 3.2.1)

https://issues.apache.org/jira/browse/MNG-3832

有趣的是此JIRA问题的评论:

Interesting is a comment in this JIRA issue:

不确定发生了什么,但这似乎可以在Maven 3.0.3中使用以下方法:

Not sure what's going on, but this seems to work in Maven 3.0.3, using this:

<exclusion>
    <groupId>*</groupId>
    <artifactId>*</artifactId>
</exclusion>

但是,这会产生以下警告:

However, this produces these warnings:

[警告]值为'*'的my.groupid:my.artifactid:ejb客户端的'dependencies.dependency.exclusions.exclusion.groupId'与有效的ID模式不匹配. @第31行,第30列

[WARNING] 'dependencies.dependency.exclusions.exclusion.groupId' for my.groupid:my.artifactid:ejb-client with value '*' does not match a valid id pattern. @ line 31, column 30

[警告] my.groupid:my.artifactid:ejb客户端的'dependencies.dependency.exclusions.exclusion.artifactId'与值'*'不匹配有效的ID模式. @第32行,第33列

[WARNING] 'dependencies.dependency.exclusions.exclusion.artifactId' for my.groupid:my.artifactid:ejb-client with value '*' does not match a valid id pattern. @ line 32, column 33

所以我可能不应该这样做,但是确实可以.

So I probably shouldn't be doing it, but it does work.

因此,您也许可以在Maven 3.0.3或更高版本中使用artifactId通配符并使其正常运行,但是会发出警告,并且不能保证与更高版本的兼容性.

So you might be able to use an artifactId wildcard in Maven 3.0.3 or later and have it work, but with warnings and with no guarantee of compatibility with later versions.

这篇关于如何从Maven组中排除所有工件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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