【问题标题】:Why doesn't Maven versions plugin update the locally defined property?为什么 Maven 版本插件不更新本地定义的属性?
【发布时间】:2021-05-15 11:56:10
【问题描述】:

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

【问题讨论】:

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


    【解决方案1】:

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

    该命令是非递归的,因此它不知道属性magic-tool.version 用于non-functional app &gt; child poms &gt; dependencies

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

    【讨论】:

      猜你喜欢
      • 2016-07-24
      • 2018-09-02
      • 2023-04-08
      • 1970-01-01
      • 2017-12-24
      • 2011-01-31
      • 1970-01-01
      • 1970-01-01
      • 2014-11-03
      相关资源
      最近更新 更多