maven-antrun-plugin 如果两个可能条件中的任何一个成立,则跳过目标 [英] maven-antrun-plugin skip target if any of two possible conditions holds
问题描述
我可以通过两个属性A和B传递给maven
I can pass two properties A and B to maven via
mvn test -DA=true
或
mvn test -DB=true
如果定义了 A 或 B,我希望跳过一个目标.我发现只有这样考虑 A 时才有可能:
If either A or B is defined i want a target to be skipped. I found it was possible when only A was considered like this:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>skiptThisConditionally</id>
<phase>test</phase>
<configuration>
<target name="anytarget" unless="${A}">
<echo message="This should be skipped if A or B holds" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
现在也必须考虑 B.这可以做到吗?
Now B has to be considered too. Can this be done?
马蒂亚斯
推荐答案
我会使用一个外部 build.xml
文件来实现,它允许您定义多个目标并结合 antcall
所以使用一个额外的虚拟目标,只是为了检查第二个条件.
I would do that with an external build.xml
file allowing you to define multiple target combined with antcall
and so using one additional dummy target, just to check the second condition.
pom.xml
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>skiptThisConditionally</id>
<phase>test</phase>
<configuration>
<target name="anytarget">
<ant antfile="build.xml"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
和 build.xml
and the build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="SkipIt" default="main">
<target name="main" unless="${A}">
<antcall target="secondTarget"></antcall>
</target>
<target name="secondTarget" unless="${B}">
<echo>A is not true and B is not true</echo>
</target>
</project>
<小时>
如果您只有 2 个条件,则另一种解决方案:将 <skip>
配置属性用于一个条件(即 maven 的东西)和 unless
(即 ant 的东西)对于其他条件:
Alternative solution if you only have 2 conditions: using the <skip>
configuration attribute for one condition (i.e. maven stuff) and the unless
(i.e. ant stuff) for the other condition:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>skiptThisConditionally</id>
<phase>test</phase>
<configuration>
<skip>${A}</skip>
<target name="anytarget" unless="${B}">
<echo>A is not true and B is not true</echo>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
这篇关于maven-antrun-plugin 如果两个可能条件中的任何一个成立,则跳过目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!