Search code examples
javamavenversions-maven-plugin

Escape Maven properties on the command line


I am trying to call versions:set -DnewVersion=${revision}, but without ${revision} being replaced.

I tried to escape the $ as \$ or $$, but this did not work.

Any idea how to achieve this?


Solution

  • There is a trick to make Maven treat properties starting with $ as strings instead of trying to substitute them:

    ./mvnw versions:set -Ddollar='$' -DnewVersion='${dollar}{revision}'
    

    The pom.xml contains the desired result:

    <version>${revision}</version>
    

    A simpler but less elegant idea is to use sed:

    ./mvnw versions:set -DnewVersion='@revision@'
    sed -i '' 's|@revision@|${revision}|' pom.xml