如何获取Maven groupId,artifactId和&项目版本到命令行 [英] How to get Maven groupId, artifactId & project version to the command line
问题描述
我想从命令行中检索 groupId,artifactId和& Maven项目的版本.
本主题中的建议解决方案"如何将Maven项目版本获取到bash命令行"是使用以下插件:
The proposed solution in this topic "How to get Maven project version to the bash command line" is to use the following plugin:
mvn org.apache.maven.plugins:maven-help-plugin:2.2:evaluate -Dexpression=project.artifactId
它运作良好,但我不知道如何同时将project.groupId, project.artifactId & project.version
设置为 -Dexpression 参数.
It works well but I can't figure out how to set, at the same time, the project.groupId, project.artifactId & project.version
to the -Dexpression argument.
我避免每次使用不同的 -Dexpression 参数启动3次Maven命令...
I would avoid launching 3 times the Maven command with a different -Dexpression argument each time...
思考
目前,我通过执行以下操作来检索数据:
For the moment, I retrieve data by doing the following:
local pom_groupid=`mvn org.apache.maven.plugins:maven-help-plugin:2.2:evaluate -Dexpression=project.groupId |grep -Ev '(^\[|Download\w+:)'`
local pom_artifactid=`mvn org.apache.maven.plugins:maven-help-plugin:2.2:evaluate -Dexpression=project.artifactId |grep -Ev '(^\[|Download\w+:)'`
local pom_version=`mvn org.apache.maven.plugins:maven-help-plugin:2.2:evaluate -Dexpression=project.version |grep -Ev '(^\[|Download\w+:)'`
推荐答案
这是另一种不需要创建Maven插件的方法,即使Olivier已经证明制作它很容易.
Here's another approach that doesn't require creating a Maven plugin even though Olivier has shown that it is pretty easy to make one.
mvn -q -Dexec.executable = echo -Dexec.args ='$ {project.groupId} $ {project.artifactId} $ {project.version}'-非递归exec:exec 2>/dev/空
mvn -q -Dexec.executable=echo -Dexec.args='${project.groupId} ${project.artifactId} ${project.version}' --non-recursive exec:exec 2>/dev/null
请注意,这是针对linux环境量身定制的.在Windows上,您可能会创建一个批处理文件,以打印其输入内容或其他内容.
Note that this is tailored to the linux environment. On windows you could probably create a batch file that prints its input or something.
这种方法的一个缺点是您可能必须在上述命令的末尾(在2>/dev/null
之后)添加| grep -v "something"
,以过滤掉一些maven打印到stdout的文本.就我而言,只有一行要过滤的文字只会出现在我的公司中.
One drawback of this approach is that you may have to add | grep -v "something"
to the very end of the command above (after the 2>/dev/null
) to filter out some text that maven prints to stdout. In my case I only had one line of text to filter that'll only appear at my company.
Credit where it is due: I adapted this info from this other StackOverflow thread.
这篇关于如何获取Maven groupId,artifactId和&项目版本到命令行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!