当属性值字符串与属性名称相同时,是否可以转义maven属性插值?

nat*_*tke 7 maven

我正在尝试定义maven属性:

<properties>
  <property>$${property}</property>
</property>
Run Code Online (Sandbox Code Playgroud)

Maven尝试扩展$ {property},我收到以下错误:

[ERROR]     Resolving expression: '${property}': Detected the
     following recursive expression cycle in 'property': [property] -> [Help 2]
Run Code Online (Sandbox Code Playgroud)

我尝试过各种各样的组合试图逃避它,但没有成功:

$$
\$
\$$
Run Code Online (Sandbox Code Playgroud)

等等

注意:当属性值与名称不同时,插值将被转义.

这可能吗?

Mor*_*fic 1

由于您似乎无法构建 Maven 属性(即使具有中间属性),也许您可​​以保留 2 个单独的属性并在需要的地方将它们连接起来。假设您想要填充文件中的某些属性。

在POM中定义2个变量:

<properties>
    <property>{property}</property>
    <dollar>$</dollar>
</properties>
Run Code Online (Sandbox Code Playgroud)

在文件中定义属性时使用两者:

# variable from file which is to be filtered
whatever=${dollar}${property}
Run Code Online (Sandbox Code Playgroud)

过滤后你会得到:

# variable from file which is to be filtered
whatever=${property} 
Run Code Online (Sandbox Code Playgroud)


使用怎么样&amp;?配置例如:

  <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>
Run Code Online (Sandbox Code Playgroud)

将输出:

[INFO] --- echo-maven-plugin:0.2:echo (default) @ XXXX ---
[INFO] property=[&{property}]
Run Code Online (Sandbox Code Playgroud)