如何获取Maven工程的project.version信息
linux-dash
A beautiful web dashboard for Linux
项目地址:https://gitcode.com/gh_mirrors/li/linux-dash
·
我敢打赌,您曾经遇到过在命令行上获得Maven项目版本的情况。所以问题是如何得到它?我已经看到了很多解决方案,通过使用Linux工具,如grep, cat或awk等,也看到了很多解决方案,
如使用这样的exec-maven-plugin:
VERSION=$(mvn -q \
-Dexec.executable="echo" \
-Dexec.args='${project.version}' \
--non-recursive \
org.codehaus.mojo:exec-maven-plugin:1.6.0:exec)
pom的配置如下:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>echo</executable>
<arguments>
<argument>${project.version}</argument>
</arguments>
</configuration>
</plugin>
不幸的是,上面的方法不适用于Windows。
从maven-help-plugin:3.1.0 开始,这件事变得很容易。
mvn org.apache.maven.plugins:maven-help-plugin:3.1.0:evaluate -Dexpression=project.version -q -DforceStdout
这将准确地在stdout上打印出项目的版本,而不是其他任何东西。也没有打印出换行,所以很容易在脚本中使用:
VERSION=$(mvn org.apache.maven.plugins:maven-help-plugin:3.1.0:evaluate -Dexpression=project.version -q -DforceStdout)
如果你在pom文件或项目的父pom中正确地固定了插件的版本:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-help-plugin</artifactId>
<version>3.1.0</version>
</plugin>
那么你就可以这样简化:
VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
除了提取版本,你也可以从pom文件中提取其他信息,如下:
GROUPID=$(mvn help:evaluate -Dexpression=project.groupId -q -DforceStdout)
除了提取版本,你也可以从pom文件中提取其他信息,如下:
GROUPID=$(mvn help:evaluate -Dexpression=project.groupId -q -DforceStdout)
像下面这样更复杂的表达也是可能的:
GROUPID=$(mvn help:evaluate \
-Dexpression=project.dependencyManagement.dependencies[0].groupId \
-q -DforceStdout \
)
原文链接:
A beautiful web dashboard for Linux
最近提交(Master分支:4 个月前 )
186a802e
added ecosystem file for PM2 5 年前
5def40a3
Add host customization support for the NodeJS version 5 年前
AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。
更多推荐


所有评论(0)