-->

行家-antrun-插件跳过目标如果任何的两种可能的条件成立(maven-antrun-plugin

2019-07-20 08:57发布

我可以通过两个属性A和B经由到Maven

 mvn test -DA=true

要么

 mvn test -DB=true

如果A或B被定义我想要跳过的对象。 我发现这是可能的时候只有A被认为是这样的:

  <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太考虑。 可以这样做?

马蒂亚斯

Answer 1:

我会做与外部build.xml文件允许你定义多个目标联合antcall因此使用一个额外的假目标,只是为了检查第二个条件。

的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文件

    <?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>配置属性对一个条件(即行家东西)和unless (即蚂蚁的东西)的其他条件:

<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 skip target if any of two possible conditions holds