首页 > 解决方案 > Maven 构建未使用模型的更新版本(pom.xml)

问题描述

我有一个 Maven 项目,我确实从用户那里获得了新的项目版本:

Current Version = 1.0.0
<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>versions-maven-plugin</artifactId>
    <version>2.7</version>
    <executions>
        <execution>
            <phase>validate</phase>
                    <goals>
                        <goal>set</goal>
                    </goals>
            </execution>
        </executions>
    </plugin>
Current Version = 2.0.0

之后我调用了我自己的自定义插件,它运行一组计算并将一个字符串附加到版本

Current Version = 2.0.0
<groupId>mygroup</groupId>
    <artifactId>my artifact</artifactId>
    <version>1.0.0</version>
    <executions>
       <execution>
        <phase>process-sources</phase>
            <goals>
                <goal>validate</goal>
            </goals>
        </execution>
    </executions>
Current Version = 2.0.0-AddedString

但是当我运行其他插件时,例如:

<groupId>com.github.ekryd.echo-maven-plugin</groupId>
    <artifactId>echo-maven-plugin</artifactId>
        <executions>
        <execution>
            <id>end</id>
            <goals>
            <goal>echo</goal>
            </goals>
            <phase>process-resources</phase>
            <configuration>
            <message>${project.version}</message>
            </configuration>
     </execution>
</executions> 

这给了我结果:“1.0.0”应该是“2.0.0-AddedString”

但为什么?以及如何解决这个问题?我需要所有插件都使用新版本并使用它。

标签: javamavenpom.xmlmaven-pluginversioning

解决方案


为此,您需要单独运行 Maven。

如果你运行类似的东西mvn versions:set -DnewVersion=2.0.0 my:plugin,那么my:plugin将看到启动命令之前的版本,而不是2.0.0在两者之间设置的版本。

因此,当您有更改 POM 的目标时,您需要在单独的 Maven 运行中调用它们,即 firstmvn versions:set -DnewVersion=2.0.0和 then mvn my:plugin


推荐阅读