如何在 Ant 中从 Mavens 的 pom 中获取项目版本 [英] How to get project version from Mavens's pom in Ant
问题描述
我有 maven 项目和 ant 任务.在 ant 任务中,我想从 pom.xml 获取版本属性.如何获得?
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?
在 pom.xml 中:
In pom.xml: <version>2.03.010</version>
推荐答案
要从 POM 访问版本,您可以使用以下命令:
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
您可以:
- 将 JAR 放在 Ant lib 目录中,并将其包含在 CLASSPATH 环境变量中
- 使用 -lib 命令行参数将其传递给 Ant
- 使用 typedef 声明.这允许您将 Ant Tasks 的库存储在您喜欢的任何位置,并将其放置在构建文件中.
使用选项 2. 您可以按如下方式修改您的项目以使 ant 了解 maven-ant-tasks 架构:
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>
使用选项 3.您指定 typedef 如下(假设 maven-ant-tasks jar 在您的项目的 lib 目录中):
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>
这篇关于如何在 Ant 中从 Mavens 的 pom 中获取项目版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!