maven-antrun-plugin skip target if any of two possible conditions holds

匆匆过客 提交于 2019-12-01 09:22:32

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>

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>

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>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!