【问题标题】:Maven build is not using the updated version of model(pom.xml)Maven 构建未使用模型的更新版本(pom.xml)
【发布时间】:2020-05-30 07:05:02
【问题描述】:

我有一个 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】:

    为此,您需要单独运行 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

    【讨论】:

    • 谢谢 JF,是否有运行“maven 运行”的序列?例如,将我所有的 maven 运行放在一个文件或一个我可以运行多个“maven run”的解决方案中。
    • 通常,你使用像 Jenkins 这样的构建服务器。
    • 我有这个问题,我没有任何构建服务器,它使任务有点复杂,你认为在一个shell脚本中多次运行并通过exec插件运行它是否明智? ?(我猜不是因为 exec 插件也在当前运行中运行)
    • 也许您可以这样做,但需要考虑不同的事情。 1. 如果你专业地做这个项目而不只是作为一个私人项目,那么首先设置一个构建服务器真的很有用。 2. 如果您真的需要放入自定义插件中的自定义逻辑,您应该仔细考虑。很多时候,你试图重新发明轮子,或者你试图做一些违背 Maven 哲学的事情。
    • 抱歉,在我写完我的文章后看到了你的最后一条评论。 Gitlab 应该能够构建 Maven 构建所需的管道,但我从未使用过。
    猜你喜欢
    • 2020-05-15
    • 1970-01-01
    • 2018-04-28
    • 1970-01-01
    • 2017-12-24
    • 1970-01-01
    • 2023-03-06
    • 1970-01-01
    • 2015-08-02
    相关资源
    最近更新 更多