java - 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”
但为什么?以及如何解决这个问题?我需要所有插件都使用新版本并使用它。
解决方案
为此,您需要单独运行 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
。
推荐阅读
- sparql - 在 RDF 图中为文字定义数据类型有什么好处?
- javascript - 如何修复通知框插入符号?
- postgresql - SELECT ... WHERE t1.tag = 'bob' AND t2.tag = 'foo' AND t1.idx = t2.idx 在同一张桌子上
- html - 如何将搜索图标浮动到右侧
- python - 双 for 循环中的 Keras 模型
- python - 带有重复项的 Pandas 枢轴
- c# - 返回 400 时无法再从 Web 请求中获得响应
- javascript - 在 textarea 中键入时,JavaScript 表单验证消息不断触发
- laravel - Laravel Summernote 在显示中
- html - 如何根据屏幕大小允许多个列大小?