【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. Rectangle Puzzle CodeForces - 281C (几何)

    You are given two rectangles on a plane. The centers of both rectangles are located in the origin of ...

  2. 网络协议相关面试问题-TLS与SSL握手

    HTTPS是什么? HTTPS并不是一个单独的协议,而是对工作在一加密连接(SSL / TLS)上的常规HTTP协议.通过在TCP和HTTP之间加入TLS(Transport Layer Securi ...

  3. (转载)了解Android 4.1,之三:黄油项目 —— 运作机理及新鲜玩意

    Welcome back to GTKA, everyone's favorite investigative series where we learn all about the newest v ...

  4. luogu【模板】线性筛素数 (Miller-Rabin素数测试模板)

    这个感觉还是挺好理解的,就是复杂度证明看不懂~ Code: #include <cstdio> #include <algorithm> #include <cstrin ...

  5. Java进阶知识06 Hibernate一对一单向外键关联(Annotation+XML实现)

    1.Annotation 注解版 1.1.创建Husband类和Wife类 package com.shore.model; import javax.persistence.Entity; impo ...

  6. noi.ac #543 商店

    我们考虑可并堆维护,从深到浅贪心选取. 用priority_queue启发式合并的话,是60pts: #include<iostream> #include<cstdio> # ...

  7. 顺序表应用8:最大子段和之动态规划法(SDUT 3665)

    Problem Description 给定n(1<=n<=100000)个整数(可能为负数)组成的序列a[1],a[2],a[3],-,a[n],求该序列如a[i]+a[i+1]+-+a ...

  8. css实现9宫格

    html <div class="nine"> <ul> <li>1</li> <li>2</li> < ...

  9. Codeforces 785 D.Anton and School - 2(组合数处理)

    Codeforces 785 D.Anton and School - 2 题目大意:从一串由"(",")"组成的字符串中,找出有多少个子序列满足:序列长度为偶 ...

  10. js 获取地址栏信息,可以传递多个参数

    //获取多个地址栏信息,name为地址栏参数名,可以传递多个参数 // 形式为 .html?id=12&a=2 function getQueryString(name){ var reg = ...