【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

[转] Maven 从命令行获取项目的版本号的更多相关文章

  1. Maven 命令行创建项目时 Could not find goal ‘create’ in plugin org.apache.maven.plugins:...

    使用maven3.3.9 版本,进行命令行创建项目时输入以下命令创建失败 mvn archetype:create -DgroupId=com.zang.maven  -DartifactId=sys ...

  2. maven 骨架命令行创建

    项目的骨架maven 约定在项目的根目录下放置pom.xml,在src/main/java目录下放置主代码,在src/test/java下放置项目的测试代码. 这些基本的目录结构和pom.xml文件的 ...

  3. egret命令行编译项目时 版本不对应的问题

    egret 命令行编译项目时 如使用 egret build -e 会出现版本不对应的问题 分析原因 A,B项目 A项目使用1.8的egret引擎, B项目使用2.5引擎 但本地引擎升级至2.5.5, ...

  4. cocos命令行生成项目

    cocos命令行生成项目: cocos new GoodDay(项目名称) -p com.boleban.www(包名字) -l cpp(项目类型) -d D:\DevProject\cocos2dx ...

  5. Shell 命令行获取本机IP,grep的练习

    Shell 命令行获取本机IP,grep的练习 在 mac 下面输入 ifconfig 或者在 linux 下面输入 ip a 就可以得到我们的网卡信息.不过通常情况下,我们需要查看的是我们的IP地址 ...

  6. 命令行获取docker远程仓库镜像列表

    命令行获取docker远程仓库镜像列表 获取思路 通过curl获取镜像tag的json串,解析后得到${image}:${tag}的格式 curl获取示例 # curl [:-s] ${API}/${ ...

  7. python命令行获取参数

    python命令行获取参数 import sys # python获取参数 input_file = sys.argv[1] output_file = sys.argv[2] print(input ...

  8. maven命令行创建项目问题

    今天在命令行下创建maven项目,使用的是create命令,但是一直失败,网上查找原因说archetype:create命令已经过期,需要使用 archetype:generate 来进行代替 加上了 ...

  9. [深入Maven源代码]maven绑定命令行参数到具体插件

    maven的插件 我们知道Maven具体构建动作都是由插件执行的,maven本身只是提供一个框架,这样就提供了高度可定制化的功能,我们用maven命令执行比如mvn clean package这样的命 ...

随机推荐

  1. Python:多进程。

    参考:https://www.liaoxuefeng.com/wiki/1016959663602400/1017628290184064 Python程序实现多进程(multiprocessing) ...

  2. 集合(七) Set—HashSet,TreeSet和LinkedHashSet

    四.Set Set和List一样,也是继承Collection的接口,但Set是不包含重复元素的集合.由于先啃下Map,Set的难度将会大幅减小.因为Set基本上都是以Map为基础实现的,例如两个主要 ...

  3. CA认证和证书

    一些概念: PKI:Public Key Infrastructure 签证机构:CA(Certificate Authority) 注册机构:RA(Register Authority) 证书吊销列 ...

  4. java 面试题摘要

    5.1 什么是线程 线程是操作系统能够进行运算调度的最小单位,它被包含在进程之中,是进程的实际运作单位, 可以使用多线程对运算提速. 5.2 线程和进程有什么区别 (1)进程是资源的分配和调度的一个独 ...

  5. 嵌入式Linux下CAN总线配置

    问题背景:本人开发板使用的是迅为iTOP4412精英版,额外购买的CAN/485模块,如下图: 但是插上模块之后,在终端使用ifconfig can0命令发现开发板读不到CAN设备,显示“ifconf ...

  6. 浅析BFC及其作用

    本文链接:https://blog.csdn.net/riddle1981/article/details/52126522

  7. 5 解析器、url路由控制、分页、渲染器和版本

    1 数据解析器 1 什么是解析器 相当于request 中content-type 对方传什么类型的数据,我接受什么样的数据:怎样解析 无论前面传的是什么数据,都可以解开 例如:django不能解析j ...

  8. Mysql历史版本下载地址

    Mysql历史版本下载地址:http://downloads.mysql.com/archives/community/

  9. webpack5持久化缓存

    Opt-in webpack 旨在注重构建安全而非性能.我们没有打算默认启用这一功能,主要原因在于此功能虽然有 95% 几率提升性能,但仍有 5% 的几率中断你的应用程序/工作流/构建. 什么是缓存失 ...

  10. 在java下面配置xml导致idea编译失败

    1.今天遇到一个问题在java配置dao.xml的时候导致,idea编译失败 然后把pom.xml上面的 <build> <resources> <resource> ...