问题
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}
}
回答1:
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.
来源:https://stackoverflow.com/questions/10554019/using-build-number-plugin-in-maven-profile-to-build-modules