Search code examples
javamavenantmaven-2maven-antrun-plugin

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.


Solution

  • 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>