当属性值字符串与属性名称相同时,是否可以转义Maven属性插值? [英] Is it possible to escape maven property interpolation when the property value string is the same as the property name?
问题描述
我正在尝试定义一个maven属性:
I am trying to define a maven property:
<properties>
<property>$${property}</property>
</property>
Maven尝试扩展$ {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:
$$
\$
\$$
等等等
注意:当属性值与名称不同时,插值将转义.
Note: the interpolation is escaped when the property value is not the same as the name.
这可能吗?
推荐答案
由于似乎无法构建Maven属性(即使具有中间属性),因此也许可以保留2个单独的属性并将其连接到需要的位置.假设您要填充文件中的某些属性.
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.
在POM中定义2个变量:
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}
<罢工> 使用
&
怎么办?这样的配置:
&
? A configuration such as:
<properties>
<property>&{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>
将输出:
[INFO] --- echo-maven-plugin:0.2:echo (default) @ XXXX ---
[INFO] property=[&{property}]
这篇关于当属性值字符串与属性名称相同时,是否可以转义Maven属性插值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!