繁体   English   中英

这是使用执行器插件来执行特定Spring版本的正确方法吗?

[英]Is this the correct way to enforce a specific Spring version using the enforcer plugin?

我希望使用maven-enforcer插件bannedDependencies规则来强制执行特定的Spring版本(3.1.2)。

这是配置执行程序插件以实现该目标的正确方法吗?

<configuration>
    <rules>
        <bannedDependencies>
            <searchTransitive>true</searchTransitive>
            <excludes>
                <exclude>org.springframework</exclude>
            </excludes>
            <includes>
                <include>org.springframework:*:3.1.2</include>
            </includes>
        </bannedDependencies>
    </rules>
    <fail>true</fail>
    <failFast>true</failFast>
    <ignoreCache>true</ignoreCache>
</configuration>

上面的代码似乎可以正常工作,并且在命令行上执行了mvn enforcer:enforce突出显示了v3.1.0或org.springframework:spring-oxm被作为传递依赖项引入。

似乎还可能要使用dependencyConvergence规则,但是它突出显示了许多依赖项错误,这些错误会被maven自动排除为“冲突”。

这是一个包含更多上下文的代码段:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-enforcer-plugin</artifactId>
            <version>${maven.enforcer.plugin}</version>
            <executions>
                <execution>
                    <id>enforce-versions</id>
                    <goals>
                        <goal>enforce</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                        <rules>
                            <bannedDependencies>
                                <searchTransitive>true</searchTransitive>
                                <excludes>
                                    <exclude>org.springframework</exclude>
                                    <exclude>org.springframework.security</exclude>
                                    <exclude>org.slf4j</exclude>
                                </excludes>
                                <includes>
                                    <include>org.springframework:*:${spring.version}</include>
                                    <include>org.springframework.security:*:${spring-security.version}</include>
                                    <include>org.slf4j:*:${slf4j.version}</include>
                                </includes>
                            </bannedDependencies>
                            <requireJavaVersion>
                                <version>${enforce.jdk.version}</version>
                            </requireJavaVersion>
                        </rules>
                        <fail>true</fail>
                        <failFast>true</failFast>
                        <ignoreCache>true</ignoreCache>
            </configuration>
        </plugin>
 .....
</plugins>

上一个问题中的bannedDependencies代码段无效,因为<include>标签无法理解groupId:artifactId:version:type表示法。 因此,通配符不能用于替换整个部分来传达include all versions of ALL artifacts in a group

但是,通过使用maven 依赖关系版本范围 ,可以强制执行特定的依赖关系。

给定工件的以下版本(按发布的顺序):

3.0.03.0.13.1.03.2.0.RELEASE3.3.0

假设我们要告诉3.2.0.RELEASE执行程序插件排除3.2.0.RELEASE所有内容,那么唯一的方法是:

exclude versions X where X < DESIRED_VERSION OR X > DESIRED VERSION

上面的意思实际上是: exclude all versions X where X != DESIRED_VERSION

由于Maven依赖版本符号不允许使用“非版本”符号,因此必须结合使用小于和大于符号,如下所示:

(,3.2.0.RELEASE),(3.2.0.RELEASE,)

这意味着: version < '3.2.0.RELEASE' or version > '3.2.0.RELEASE'

最后,一段有效的代码片段如下:

<bannedDependencies>
    <searchTransitive>true</searchTransitive>
    <excludes>
        <exclude>org.springframework:*:(,${spring.version}),(${spring.version},)</exclude>    
    </excludes>
</bannedDependencies>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM