Maven的antrun-插件跳过目标如果有两个可能的条件下保存 [英] maven-antrun-plugin skip target if any of two possible conditions holds
问题描述
我可以通过
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
文件允许你定义多个目标与<结合code> 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个条件:使用&LT;跳过&GT;
的一个条件配置属性(即Maven的东西)和除非
(即蚂蚁的东西)为其他条件:
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-插件跳过目标如果有两个可能的条件下保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!