In order to use the pom task, you will first need to define a pom (typically pom.xml). An example pom is provided here:
<project> <modelVersion>4.0.0</modelVersion> <groupId>com.mycompany.project</groupId> <artifactId>project-model</artifactId> <version>1.0-SNAPSHOT</version> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.2</version> <scope>test</scope> </dependency> <dependency> <groupId>org.codehaus.modello</groupId> <artifactId>modello-core</artifactId> <version>1.0-alpha-2-SNAPSHOT</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.4</version> <scope>provided</scope> </dependency> </dependencies> </project>
These elements represent:
This is all that is required for most projects. However, it is also possible to use other fields available in Maven to describe your project, and reference them from your build script.
To access a part of the POM as an Ant property, you must define it as a reference. For example, to access the version from a POM, you can use the following:
<artifact:pom id="mypom" file="pom.xml" /> <echo>The version is ${mypom.version}</echo>
You can also access nested parts of the POM. For example, you can read the default value of the directory element within the build element using a . separator.
<artifact:pom id="mypom" file="pom.xml" /> <echo>The build directory is ${mypom.build.directory}</echo>
For more information on the elements available in the POM, see the descriptor reference.
The pom task can be used in combination with the dependencies task to declare a list of dependencies.
<artifact:pom id="mypom" file="pom.xml" /> <artifact:dependencies filesetId="mydeps" pomRefId="mypom" />
In this example, the dependencies task will resolve the list of dependencies in the pom and add them to the fileset.
POM profiles can be activated or deactivated using the nested profile element. For example to activate a profile called my-profile.
<artifact:pom id="maven.project" file="pom.xml"> <profile id="my-profile"/> </artifact:pom>
This can also be used to deactivate a POM profile that is active by default.
<artifact:pom id="maven.project" file="pom.xml"> <profile id="my-default-profile" active="false"/> </artifact:pom>