看起来好像你有条件地激活一个配置文件 ......
<profiles>
<profile>
<activation>
<property>
<name>environment</name>
<value>test</value>
</property>
</activation>
...
</profile>
</profiles>
Run Code Online (Sandbox Code Playgroud)
将环境变量定义为值时,将激活该配置文件,test如以下命令中所示:
mvn ... -Denvironment=test
您可以使用 maven-antrun-plugin 有条件地设置属性。示例设置install.path+ 回显值:
<plugin>
<!-- Workaround maven not being able to set a property conditionally based on environment variable -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<exportAntProperties>true</exportAntProperties>
<target>
<property environment="env"/>
<condition property="install.path" value="${env.INSTALL_HOME}" else="C:\default-install-home">
<isset property="env.INSTALL_HOME" />
</condition>
<echo message="${install.path}"/>
</target>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
如果系统属性不可接受,您只需在POM文件中定义属性并在需要时覆盖:
<project>
...
<properties>
<foo.bar>hello</foo.bar>
</properties>
...
</project>
Run Code Online (Sandbox Code Playgroud)
您可以参考POM中的其他地方引用此属性${foo.bar}.要在命令行上覆盖,只需传递一个新值:
mvn -Dfoo.bar=goodbye ...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17525 次 |
| 最近记录: |