maven update pom property

Ok, i found some case of solution. I'm using maven-replacer-plugin where: my properties definition in pom.xml :

        <properties>
        <abc.def>aaaaa</abc.def>
    <properties>

my plugin configuration :

                <plugin>
           <groupId>com.google.code.maven-replacer-plugin</groupId>
           <artifactId>replacer</artifactId>
           <version>1.5.2</version>
           <configuration>
               <file>pom.xml</file>
               <replacements>
                   <replacement>
                       <token>${abc.def}</token>
                       <value>${replacer.abc.def}</value>
                   </replacement>         
               </replacements>
           </configuration>
        </plugin>

and finally my maven invocation :

mvn replacer:replace -Dreplacer.abc.def=XYZ

It works for me but I don know is there any better way to achieve it with maven-relase-plugin and/or versions-maven-plugin as @khmarbaise and @Conan said.


I agree with @khmarbaise above, the versions-maven-plugin will do just this, or you could move to the Maven Release Plugin if you want a much heftier approach to managing your versions, but you could also just run a script to sed the pom.xml file using Jenkins' BUILD_NUMBER environment variable, which is a quicker and dirtier approach.


mvn versions:update-properties -Dproperties=[XYZ] -DincludeProperties={abc.def}

Read more here. and here.

In short:

In versions-maven-plugin, the update-properties goal sets properties to the latest versions of specific artifacts.

includeProperties is a comma separated list of properties to update.

properties are any restrictions that apply to specific properties.


The accepted answer does not work for arbitrary values since it performs sanity checks (links to the documentation for set-property goal since for some reason the documentation for update-properties does not mention this).

To set some arbitrary value on a property use set-property since - as documented - it skips sanity checks:

mvn versions:set-property -Dproperty=your.property -DnewVersion=some_value

Tags:

Plugins

Maven