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