Thursday, September 13, 2007

How to add a Usage message to maven builds

The easier way is to use the antrun plug-in's run goal, bind it to the validate phase (the first phase in the list of maven 2.0 phases), and configure the plug-in to echo the usage string.
e.g.


<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.giri</groupid>
<artifactid>com.giri</artifactid>
<name>UsageExample</name>
<version>1.0.0</version>
<description>
MavenUsageExample-
Usage: mvn [-Dplatform.type=local/dev/qa/stage/prod]
--platform.type is taken for resources to package.
</description>
<properties> <!-- Defaults to local. To override, define like: mvn -Dplatform.type=dev -->
<platform.type>local</platform.type>
</properties>
<build>
<defaultgoal>assembly:assembly</defaultgoal>
<sourcedirectory>src/java</sourcedirectory>
<resources> <!-- only include platform related resources -->
<resource>
<directory>
src/resource/${platform.type}
</directory>
</resource>
</resources>
...
<plugins>
...
<plugin>
<artifactid>maven-antrun-plugin</artifactid>
<executions>
<execution>
<id>echo-usage</id>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>***********************</echo>
<echo>
Usage:
mvn [-Dplatform.type=local/dev/qa/stage/prod]
</echo>
<echo>
-Dplatform.type is optional.
If not specified, default is local
</echo>
<echo>***********************</echo>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
...
</build>
</project>


No comments:

Post a Comment