[英]How to get maven version number inside POM
I need to get maven version number (eg 3.0.5, 3.1.0) from inside pom.xml file I need it to be able to add correct dependencies for: 我需要从pom.xml文件中获取maven版本号(例如3.0.5,3.1.0)我需要它才能为以下内容添加正确的依赖项:
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
<version>3.0.5</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.0.5</version>
</dependency>
Version 3.1.0 requires the libraries at the same version, same for 3.0.5. 版本3.1.0需要相同版本的库,3.0.5版本相同。 I would assume that there has to be something like
${maven.version}
in poms but I couldn't find it. 我会假设在
${maven.version}
必须有${maven.version}
,但我找不到它。
EDIT: I need the project to work in both maven 3.0 and 3.1 so I can't do it statically it has to get the version of currently running maven 编辑:我需要该项目在maven 3.0和3.1中工作所以我不能静态地做它必须获得当前正在运行的maven的版本
The best solution is to define a property like this: 最好的解决方案是定义这样的属性:
<properties>
<maven.version>3.0.3</maven.version>
</properties>
and define the dependencies with such property within your pom file. 并在您的pom文件中定义具有此属性的依赖项。
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>${maven.version}</version>
</dependency>
or 要么
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
<version>${maven.version}</version>
</dependency>
or for the plugin-api like the following: 或者对于plugin-api,如下所示:
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>${maven.version}</version>
</dependency>
For the maven-model it does not really matter if you are using 3.0.1 or 3.0.5 or 3.1 cause the model (pom.xml) hasn't been changed. 对于maven模型,如果您使用3.0.1或3.0.5或3.1并不重要,因为模型(pom.xml)尚未更改。 For the plugin-api you can use 3.0.5 and get it running in Maven 3.1 as well.
对于plugin-api,你可以使用3.0.5并让它在Maven 3.1中运行。 BTW: The above things are from a plugin which works under Maven 3.0 and 3.1.
BTW:以上内容来自一个在Maven 3.0和3.1下运行的插件。
You can add it yourself via a settings.xml
file. 您可以通过
settings.xml
文件自行添加它。
${settings.mvn.version}
would refer to: ${settings.mvn.version}
会引用:
<settings>
<mvn>
<version>3.1.0</version>
<mvn>
</settings>
Or add {$mvn.version}
directly in the pom.xml
, by using: 或者使用以下
{$mvn.version}
直接在pom.xml
添加{$mvn.version}
:
<project>
...
<properties>
<mvn.version>3.1.0</mvn.version>
</properties>
...
</project>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.