【From】https://blog.soebes.de/blog/2018/06/09/help-plugin/

I bet you have been faced with the situation to get the version of your Maven project on command line? So the question is how to get it? I have seen many solutions via using Linux tools like grepcat or awk etc. also seen many solutions like using exec-maven-plugin like this:

1
2
3
4
5
VERSION=$(mvn -q \
-Dexec.executable="echo" \
-Dexec.args='${project.version}' \
--non-recursive \
org.codehaus.mojo:exec-maven-plugin:1.6.0:exec)

Unfortunately the above approach will not work on Windows.

Starting with Maven Help Plugin Release 3.1.0 this can be done more easier like the following:

1
mvn org.apache.maven.plugins:maven-help-plugin:3.1.0:evaluate -Dexpression=project.version -q -DforceStdout

This will exactly print out the version of your artifact on stdout and nothing else. Also no line feed is printed out.

So this can be used easily in scripts like this:

1
VERSION=$(mvn org.apache.maven.plugins:maven-help-plugin:3.1.0:evaluate -Dexpression=project.version -q -DforceStdout)

If you have correctly pinned the version of your plugins in your pom file or in a parent pom of the project this can be simplified like this:

1
VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)

Apart from extracting the version you can also extract other information from the pom file like the following:

1
GROUPID=$(mvn help:evaluate -Dexpression=project.groupId -q -DforceStdout)

More sophisticated expressions like the following are possible too:

1
2
3
4
GROUPID=$(mvn help:evaluate \
-Dexpression=project.dependencyManagement.dependencies[0].groupId \
-q -DforceStdout \
)

Posted by Karl-Heinz Marbaise Jun 9th, 2018  MavenMaven-PluginsUsage

最新文章

  1. WebService入门
  2. javax.el.PropertyNotFoundException 出错
  3. mount: unknown filesystem type 'ntfs'
  4. iOS sha1加密算法
  5. 通过url给action传中文参数乱码解决方案
  6. python爬虫从入门到放弃(一)之初识爬虫
  7. C++学习-8
  8. 2. 引入springmvc
  9. windows service创建使用整合
  10. CIA402状态转换图
  11. FTP软件FileZilla 3.38.1下载
  12. 理解UDP协议的首部校验和校验和
  13. winserver2012 下安装 sqlserver2008
  14. Memcached cas 陷阱
  15. ehcache讲解及实例
  16. php 页面调转导致session丢失解决方法
  17. 使用Solrj 获取语句分词结果的代码
  18. math模块
  19. drupal pathauto的配置
  20. .NET中的六个重要概念

热门文章

  1. 在RecyclerView中集成QQ汽泡一
  2. java线程基础巩固---线程ID,优先级
  3. ajax 向php发送请求
  4. VSCode远程连接Docker
  5. npm更换成淘宝镜像源以及cnpm
  6. python面向对象基础(三)内置方法 __xx__
  7. 面向对象(oop)特征
  8. abd常用命令
  9. word文档在线预览地址
  10. tar:文件打包归档