Search code examples
javamaven-2teamcitysystem-properties

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)?


Solution

  • 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).