在maven配置文件中使用build number插件来构建模块 [英] using build number plugin in maven profile to build modules
问题描述
< groupId> com.dummy.bla .bla< /&的groupId GT;
< artifactId>父< / artifactId>
< version> 1.0-SNAPSHOT< / version>
< packaging> pom< / packaging>
< modules>
< module> A< / module>
< module> B< / module>
< module> C< / module>
< / modules>
和三个模块依赖于彼此,如链:
A< - B< - C
当我在父级下运行build时,首先生成A-1.0-SNAPSHOT.jar,然后生成B-1.0-SNAPSHOT.jar,最后是C-1.0-SNAPSHOT.jar。
然后问题是,我有另一个maven配置文件每天生成夜间构建。在我的父pom.xml中,我有:
<建立>
<个人资料>
< id> nightlybuild< / id>
< finalName> $ {artifcateId} - $ {buildNumber}< / finalName>
< plugin>
< groupId> org.codehaus.mojo< / groupId>
< artifactId> buildnumber-maven-plugin< / artifactId>
<执行>
< execution>
< phase> generate-resources< / phase>
< goals>
< goal> create< / goal>
< / goals>
< / execution>
< / executions>
< configuration>
< doCheck> false< / doCheck>
< doUpdate> false< / doUpdate>
< format> {0,date,yyyy-MM-dd_HH-mm} _ {1}< / format>
< items>
< item> timestamp< / item>
< item> $ {user.name}< / item>
< / items>
< / configuration>
< / plugin>
< / build>
然后我有问题使用配置文件nighlybuild构建所有模块,因为它首先生成A - $ {buildNumber} .jar,那么当它构建B时,它找不到A-1.0-SNAPSHOT.jar(因为在B / pom.xml下我有A作为与1.0版本的SNAPSHOT的依赖关系)。有没有反正在b下的pom.xml可以有这样的东西:
if(normal build){
依赖关系A版本是:1.0-SNAPSHOT
}
if(nightly build){
依赖一个版本是:$ {buildNumber}
}
这不是很好的做法。如果您正在更改版本,那么您必须真正发布您的工件,即使用maven-release-plugin(在夜间构建时仍可执行此操作)。
但是为了回答你的问题,没有什么可以阻止你将项目B中的依赖关系声明移动到一个配置文件中,尽管我不认为你可以使用依赖关系版本声明内的插件设置。
I have parent project "parent", which has three modules like:
<groupId>com.dummy.bla.bla</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>A</module>
<module>B</module>
<module>C</module>
</modules>
and three modules are depending on each other like a chain:
A<--B<--C
When I run the build under parent, I will have A-1.0-SNAPSHOT.jar generated first, then B-1.0-SNAPSHOT.jar, finally C-1.0-SNAPSHOT.jar.
Then problem is that, I have another maven profile to generate nightly build every day.In my parent pom.xml I have:
<build>
<profile>
<id>nightlybuild</id>
<finalName>${artifcateId}-${buildNumber}</finalName>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
<format>{0,date,yyyy-MM-dd_HH-mm}_{1}</format>
<items>
<item>timestamp</item>
<item>${user.name}</item>
</items>
</configuration>
</plugin>
</build>
Then I have problem to build all the modules using the profile "nighlybuild", because it firstly generates A-${buildNumber}.jar, then when it builds B, it fails to look for A-1.0-SNAPSHOT.jar(because under B/pom.xml I have A as a dependency with version 1.0-SNAPSHOT). Is there anyway the pom.xml under B can have something like:
if(normal build) {
dependency A version is: 1.0-SNAPSHOT
}
if(nightly build) {
dependency A version is: ${buildNumber}
}
This is not really good practice. If you're changing version, then you must really be releasing your artifacts, i.e. using maven-release-plugin (can still do that during your nightly build).
But to answer your question, nothing really stops you from moving your dependency declaration in project B into a profile though I don't think you can use properties set by plugins inside dependency version declaration.
这篇关于在maven配置文件中使用build number插件来构建模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!