Home > Build-Management, Software Engineering > Using the Maven Antrun Plugin to output the version number to a text file

Using the Maven Antrun Plugin to output the version number to a text file

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.test</groupId>
  <artifactId>write-property</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>pom</packaging>
  
  <properties>
    <version>1.0.1</version>
    <maven.build.timestamp.format>yyyyMMdd-HHmmss</maven.build.timestamp.format>
    <current.build.date>${build.timestamp}</current.build.date>
  </properties>
  
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.4</version>
        <executions>
          <execution>
            <phase>validate</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <tasks>
                <propertyfile file="version.properties" comment="Version information">
                  <entry key="version" value="${version}" />
                  <entry key="current.build.date" value="${current.build.date}" />
                </propertyfile>
              </tasks>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>
mvn validate

The Maven Plugin creates the following version.properties file:

#Version information
#Tue, 23 Oct 2012 13:09:23 +0200

version=1.0.1
current.build.date=20121023-130922
Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s