Escape Maven properties on the command line

1.7k Views Asked by At

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?

1

There are 1 best solutions below

0
Eugene Khyst On BEST ANSWER

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