gpt4 book ai didi

maven - 如何在另一个属性中引用 Maven 属性?

转载 作者:行者123 更新时间:2023-12-04 12:33:35 24 4
gpt4 key购买 nike

假设我从某处获得了一个属性文件,它具有以下定义:

dog=POODLE

在运行 maven 时,我传递了一个带有属性名称的参数来查找:
mvn clean install -animal=dog

我需要能够在 pom.xml 中检索值 "POODLE"不知道要查找的属性是什么(我还不知道我正在查找“狗”,但只知道我正在查找“动物”)。

这能做到吗?

我可以在 pom 中引用 ${animal}它将被替换为 dog ,但后来我需要查一下。

我是无辜的尝试以下,但它不会工作:
${${animal}}

谢谢!

最佳答案

如果你使用 -Danimal=${dog} 它应该可以工作.这是我的例子

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>nested-property</groupId>
<artifactId>nested-property</artifactId>
<version>0.0.1-SNAPSHOT</version>

<properties>
<dog>POODLE</dog>
</properties>

<build>
<plugins>
<plugin>
<groupId>com.soebes.maven.plugins</groupId>
<artifactId>maven-echo-plugin</artifactId>
<version>0.1</version>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>echo</goal>
</goals>
</execution>
</executions>
<configuration>
<echos>
<echo>Animal: ${animal}</echo>
</echos>
</configuration>
</plugin>
</plugins>
</build>
</project>

运行: mvn -Danimal=${dog} install
结果是
[INFO] --- maven-echo-plugin:0.1:echo (default) @ nested-property ---
[INFO] Animal: POODLE
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

关于maven - 如何在另一个属性中引用 Maven 属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15074634/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com