How to get project version from Mavens's pom in Ant

安稳与你 提交于 2019-12-21 12:29:21

问题


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

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


回答1:


The Maven Ant tasks provide some goals for POM processing

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>

Update: To use the tasks. You will need to install them. Install instructions

You can either:

  1. Place the JAR in your Ant lib directory, include it in the CLASSPATH environment variable
  2. Pass it in to Ant using the -lib command line parameter
  3. Use a typedef declaration. This allows you to store the Ant Tasks' library anywhere you like and put it's location in the build file.

With option 2. you modify your project as follows to make ant aware of the maven-ant-tasks schema:

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

With option 3. You specify the 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>



回答2:


If what you want is just to read values from pom.xml with what's included in ant already, you can use the XmlProperty task:

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

The Maven Ant Tasks are no longer maintained, by the way.



来源:https://stackoverflow.com/questions/1490914/how-to-get-project-version-from-mavenss-pom-in-ant

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!