How to get project version from Mavens pom in Ant

I have a maven project and ant for it. In the ant task, I want to get the version property from pom.xml. How to get it?

In pom.xml: <version>2.03.010</version>

+7
maven-2 ant
source share
2 answers

Maven Ant tasks provide some goals for handling POM

To access the version from POM, you can use the following:

 <artifact:pom id="mypom" file="pom.xml" /> <echo>The version is ${mypom.version}</echo> 

Update: using tasks. You will need to install them. Set instructions

You can:

  • Put the JAR in the Ant lib directory, include it in the CLASSPATH environment variable
  • Pass it to Ant using the -lib command-line option
  • Use a typedef declaration. This allows you to store the Ant Tasks' library anywhere and put it in the build file.

With option 2., you modify your project as follows so that Ant knows the maven-ant -tasks schema:

 <project ... xmlns:artifact="antlib:org.apache.maven.artifact.ant"> ... </project> 

With option 3. you specify typedef as follows (assuming the maven-ant -tasks jar is in the lib directory of your project):

 <project ... xmlns:artifact="antlib:org.apache.maven.artifact.ant"> ... <path id="maven-ant-tasks.classpath" path="lib/maven-ant-tasks-2.0.10.jar" /> <typedef resource="org/apache/maven/artifact/ant/antlib.xml" uri="antlib:org.apache.maven.artifact.ant" classpathref="maven-ant-tasks.classpath" /> ... </project> 
+12
source share

If you want to just read the values ​​from pom.xml using what is included in ant, you can use the XmlProperty task:

 <xmlproperty file="pom.xml" prefix="pom" /> <echo>The version is ${pom.project.version}</echo> 

Maven ant tasks are no longer supported.

+5
source share

All Articles