具有属性变量的 Maven 配置文件
Maven profiles with variable for properties
我正在研究 MAVEN 配置文件,我对使用变量设置属性有疑问。目前,我正在使用以下配置:
<profile>
<id>Action type D restriction</id>
<activation>
<property>
<name>actionType</name>
<value>D</value>
</property>
</activation>
<properties>
<restriction.actionType>D</restriction.actionType>
</properties>
</profile>
<profile>
<id>Action type W restriction</id>
<activation>
<property>
<name>actionType</name>
<value>W</value>
</property>
</activation>
<properties>
<restriction.actionType>W</restriction.actionType>
</properties>
</profile>
我的问题是这样的;是否有可能以某种方式使用一个带有变量的配置文件来完成相同的工作,类似于 :
<profile>
<id>Action type restriction</id>
<activation>
<property>
<name>actionType</name>
<value>[D,W]</value>
</property>
</activation>
<properties>
<restriction.actionType>${project.profiles.profile.activation.value}</restriction.actionType>
</properties>
</profile>
或者类似的东西。
也许你想要这样的东西
<profiles>
<profile>
<id>Action type restriction</id>
<activation>
<property>
<name>actionType</name>
</property>
</activation>
<properties>
<restriction.actionType>${actionType}</restriction.actionType>
</properties>
</profile>
</profiles>
谢谢图纳基。成功了。现在我的设置是这样的:
<project>
...
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<ActionType/>
</properties>
...
<profiles>
<profile>
<id>Action-type profile</id>
<activation>
<property>
<name>actionType</name>
<value>[D,W]</value>
</property>
</activation>
</profile>
</profiles>
...
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>properties.plugin</groupId>
<artifactId>Lazaruss-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<configuration>
<actionType>${actionType}</actionType>
</configuration>
...
</plugin>
</plugins>
</pluginManagement>
</build>
和运行它用命令:
mvn groupId:artefactId:version:goal -DactionType=W
它现在将我的 class 中的变量设置为 W :)
PS :注意我的 class 中的变量也被命名为 'actionType'
我正在研究 MAVEN 配置文件,我对使用变量设置属性有疑问。目前,我正在使用以下配置:
<profile>
<id>Action type D restriction</id>
<activation>
<property>
<name>actionType</name>
<value>D</value>
</property>
</activation>
<properties>
<restriction.actionType>D</restriction.actionType>
</properties>
</profile>
<profile>
<id>Action type W restriction</id>
<activation>
<property>
<name>actionType</name>
<value>W</value>
</property>
</activation>
<properties>
<restriction.actionType>W</restriction.actionType>
</properties>
</profile>
我的问题是这样的;是否有可能以某种方式使用一个带有变量的配置文件来完成相同的工作,类似于 :
<profile>
<id>Action type restriction</id>
<activation>
<property>
<name>actionType</name>
<value>[D,W]</value>
</property>
</activation>
<properties>
<restriction.actionType>${project.profiles.profile.activation.value}</restriction.actionType>
</properties>
</profile>
或者类似的东西。
也许你想要这样的东西
<profiles>
<profile>
<id>Action type restriction</id>
<activation>
<property>
<name>actionType</name>
</property>
</activation>
<properties>
<restriction.actionType>${actionType}</restriction.actionType>
</properties>
</profile>
</profiles>
谢谢图纳基。成功了。现在我的设置是这样的:
<project>
...
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<ActionType/>
</properties>
...
<profiles>
<profile>
<id>Action-type profile</id>
<activation>
<property>
<name>actionType</name>
<value>[D,W]</value>
</property>
</activation>
</profile>
</profiles>
...
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>properties.plugin</groupId>
<artifactId>Lazaruss-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<configuration>
<actionType>${actionType}</actionType>
</configuration>
...
</plugin>
</plugins>
</pluginManagement>
</build>
和运行它用命令:
mvn groupId:artefactId:version:goal -DactionType=W
它现在将我的 class 中的变量设置为 W :)
PS :注意我的 class 中的变量也被命名为 'actionType'