为什么 Maven 版本插件不更新本地定义的属性?

时间:2021-02-11 17:38:36

标签: maven pom.xml maven-versions-plugin

我正在使用 versions-maven-plugin 并且在我的顶级 pom.xml 中有几个用于 versions-maven-plugin 的配置:

<build>
    <pluginManagement>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>versions-maven-plugin</artifactId>
            <version>2.8.1</version>
            <configuration>
                <properties>
                    <property>
                        <name>magic-tool.version</name>
                    </property>
                </properties>
            </configuration>
        </plugin>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>versions-maven-plugin</artifactId>
        </plugin>
...
<reporting>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>versions-maven-plugin</artifactId>
            <reportSets>
               <reportSet>
                    <reports>
                        <report>dependency-updates-report</report>
                        <report>plugin-updates-report</report>
                        <report>property-updates-report</report>
                    </reports>
                </reportSet>
            </reportSets>
        </plugin>

还有一个属性指的是内部存储库“magic-tool”:

<properties>
     <magic-tool.version>100</magic-tool.version>

有问题的命令是

mvn clean && mvn versions:update-properties versions:commit -N -U -DincludeProperties=magic-tool.version -DallowSnapshots=true -X

这比指定将在 TeamCity 中使用的确切版本更可取 - 此命令在另一个具有几乎相同 pom.xml 和完全相同配置的应用程序中完美运行!

然而,非功能性应用程序的输出是

[DEBUG] lowerBoundArtifactVersion: 100
[DEBUG] Property ${magic-tool.version}: Current winner is: null
[INFO] Property ${magic-tool.version}: Leaving unchanged as 100

当我们的 repo 中的 magic-tool 位于 v102 时,而我们的应用程序输出正常工作:

[DEBUG] Property ${magic-tool.version}: Set of valid available versions is [1, 2, 3, 4, 5, 6, 7... 95, 96, 97, 98, 99, 100, 101, 102]
[DEBUG] Property ${magic-tool.version}: Restricting results to null
[DEBUG] lowerBoundArtifactVersion: 101
[DEBUG] Property ${magic-tool.version}: Current winner is: 102
[DEBUG] Property ${magic-tool.version}: Searching reactor for a valid version...
[DEBUG] Property ${magic-tool.version}: Set of valid available versions from the reactor is []
[INFO] Updated ${magic-tool.version} from 100 to 102

如何让非功能性应用更新此属性 magic-tool.version?

1 个答案:

答案 0 :(得分:0)

答案是该属性在 non-functional > parent pom > dependencies 中未使用,但在 functional app > parent pom > dependencies 中使用。

该命令是非递归的,因此它不知道在 magic-tool.version 中使用了属性 non-functional app > child poms > dependencies

解决方案是在顶层pom中的依赖项中主动使用/定义属性(注意将其添加到<dependencyManagement>中没有任何作用)。

相关问题