开发者

Maven system property priority

I have following pom.xml

<project>
  <properties>
    <buildNumber>dev</buildNumber>
  </properties>
  <build>
    <finalName>${project.artifactId}-$开发者_如何学编程{project.version}-${buildNumber}</finalName>
  </build>
</project>

This works fine on development machine. If I run mvn package I've got project-1.1-dev.war artifact. If I run mvn package -DbuildNumber=121 I've got package-1.1-121.war.

But out CI server (TeamCity) always got project-1.1-dev.war despite the fact that buildNumber property passed to maven (if I remove default property definition from pom.xml, maven builds artifact with correct filename).

It seems that system property resolve priority is somehow depends on platform (maven version is equals on both developer machine and TC - 2.2.1)?


That's a bit strange... Maybe you can't force the parameter given in the command line to have a highest priority than the one defined in the <properties> tag.

An idea is to use a profile that define the property buildNumber:

<profiles>
    <profile>
        <id>dev-property</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <buildNumber>dev</buildNumber>
        </properties>
    </profile>
</profiles>

So by default, buildNumber will be equals to dev value. Now, in your TeamCity command line, disable this profile with the command mvn ... -P !dev-property (the ! before a profile id indicates that the profile must be disabled).


The answer to your question lies in another question here on SO: Maven property overloading

In short, you need to pass -DbuildNumber=121 on the maven command line (on the "3 build step: maven" page), because setting system property "buildNumber" on the "6 properties and variables" page does not override the maven property.


Are you familiar with the concept of SNAPSHOT versions? Sounds like what you are trying to do, and is supported out of the box by Maven. Looks like you want to build major-minor-incremental or major-minor-dev, if you can live with major-minor-incremental-SNAPSHOT instead it should do what you want.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜