Maven构建未使用模型(pom.xml)的更新版本

问题描述 投票:0回答:1

我有一个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”]

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

java maven pom.xml maven-plugin versioning
1个回答
0
投票
您需要为此运行单独的Maven。

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

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

© www.soinside.com 2019 - 2024. All rights reserved.