Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to escape maven property interpolation when the property value string is the same as the property name?

Tags:

maven

I am trying to define a maven property:

<properties>
  <property>$${property}</property>
</property>

Maven tries to expand ${property} and I get the following error:

[ERROR]     Resolving expression: '${property}': Detected the
     following recursive expression cycle in 'property': [property] -> [Help 2]

I have tried all sorts of combinations to try to escape it, without success:

$$
\$
\$$

etc etc

Note: the interpolation is escaped when the property value is not the same as the name.

Is this possible?

like image 551
natke Avatar asked Jun 02 '14 03:06

natke


1 Answers

Since it seems you can't build a maven property (even with intermediate properties), maybe you can keep 2 separate properties and concatenate them where you need. Let's say you want to populate some property in a file.

Define the 2 variables in the POM:

<properties>
    <property>{property}</property>
    <dollar>$</dollar>
</properties>

use both when defining the property in the file:

# variable from file which is to be filtered
whatever=${dollar}${property}

and upon filtering you'll end up with:

# variable from file which is to be filtered
whatever=${property} 


What about using &amp;? A configuration such as:
  <properties>
      <property>&amp;{property}</property>
  </properties>

  ...

  <plugins>
        <plugin>
            <groupId>com.soebes.maven.plugins</groupId>
            <artifactId>echo-maven-plugin</artifactId>
            <version>0.2</version>
            <executions>
                <execution>
                    <phase>initialize</phase>
                    <goals>
                        <goal>echo</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <echos>
                    <echo>property=[${property}]</echo>
                </echos>
            </configuration>
        </plugin>
  </plugins>

will output:

[INFO] --- echo-maven-plugin:0.2:echo (default) @ XXXX ---
[INFO] property=[&{property}]

like image 160
Morfic Avatar answered Nov 03 '22 00:11

Morfic