Sometimes it is desirable to write a simple file with maven. Examples are:
With the help of the maven-antrun-plugin and the ant echo task, it is quite easy to create a file:
<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-antrun-plugin</artifactId>
      <version>1.8</version>
      <executions>
        <execution>
          <goals>
            <goal>run</goal>
          </goals>
          <phase>prepare-package</phase>
          <configuration>
            <target if="maven.create.file">
              <echo file="${project.build.outputDirectory}/META-INF/version.txt" message="version: ${project.version}" />
            </target>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>
The target element supports among other the following attributes:
If we want to create a file when the property maven.create.file is set to any value (not necessary ‘true’, it can also be ‘false’), we write:
<target if="maven.create.file">
  ...
</target>