开发者

How to disable antrun if certain file already exists?

How can I disable maven-antrun-plugin execution when certain file already exists?:

[...]
<plugin>
  <artifactId>maven-antrun-plugin</artifactId>
  <version>1.6</version>
  <executions>
    <execution>
      <phase>test</phase>
      <goals>
        <goal>run</goal>
      </goals>
      <configuration>
        <target>
          <!-- do something really complex in order to create file.txt -->
        </target>
      </configuration>
  开发者_如何学运维  </execution>
  </executions>
</build>
[...]

The execution takes some time and I don't want to repeat it every time when file.txt is already there.


Check for the presence of the file in your standalone Ant file. Example:

<target name="check-file">
    <available file="foo.bar" property="fileExists" />
</target>

<target name="time-consuming" depends="check-file" unless="fileExists">
    ...
</target>


Use a <profile> that's only active if file.txt doesn't exist:

<profiles>
    <profile>
        <id>createFile</id>
        <activation><file><missing>file.txt</missing></file></activation>
        <build><plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.6</version>
                <!-- etc -->
            </plugin>

        </plugins></build>
    </profile>
</profiles>

Reference:

  • Introduction to Build Profiles
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜