Wednesday, September 26, 2012

Pass maven properties to maven-antrun-plugin

Problem:

You want to bundle a your application jar files with other software artifacts but as maven names your jar file as magic-app-${project.version}.jar your maven-antrun-plugin fails to pick it up on its own.

Solution:
This was a persistent irritant as every time we upgraded our applications' version we needed to manually enter the same version name to build.properties and only then we can package latest jars for release.

After exploring certain unsatisfactory solution like;
Finally, got some hints from;
Update your pom as shown below to export maven properties to ant build at run time.
<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.7</version>
        <executions>
          <execution>
            <phase>package</phase>
            <configuration>
              <target>
                <property name="release.version" value="${project.version}" />                <ant antfile="build.xml" />
              </target>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
 Hope that helps.

1 comment:

Avinash Kumar said...

nice :) . one more irritating manual task removed :)