Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maven update pom property

Tags:

plugins

maven

I'm looking for a way to update pom property to given value, i.e. my pom.xml contains:

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

now i want to call :

mvn some_plugin:some_goal -Dabc.def=XYZ

and finally my pom.xml should looks like

<properties>
    <abc.def>XYZ</abc.def>
<properties>

I was reading about maven-release-plugin & versions-maven-plugin but i do not see there any matching goal.

Thank you in advance for any reply.

like image 608
Paweł Dulęba Avatar asked Jul 19 '13 06:07

Paweł Dulęba


4 Answers

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.

like image 186
OhadR Avatar answered Nov 19 '22 21:11

OhadR


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
like image 30
George Aristy Avatar answered Nov 19 '22 22:11

George Aristy


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.

like image 7
Paweł Dulęba Avatar answered Nov 19 '22 22:11

Paweł Dulęba


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.

like image 1
Conan Avatar answered Nov 19 '22 21:11

Conan