微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

我正在使用 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?

解决方法

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

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

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。