Springboot?整合maven插口調(diào)用maven?release?plugin實(shí)現(xiàn)一鍵打包功能
maven release plugin配置
參考 http://www.dbjr.com.cn/article/240857.htm 配置好pom。
整合maven-invoker使程序去執(zhí)行mvn命令
1.導(dǎo)包
<dependency> <groupId>org.apache.maven.shared</groupId> <artifactId>maven-invoker</artifactId> <version>3.1.0</version> </dependency>
注意maven-invoker版本。版本過(guò)低可能導(dǎo)致不兼容。
2.測(cè)試程序
public class MavenTest { //直接執(zhí)行mvn release:prepare -X 為交互式執(zhí)行,無(wú)法在程序進(jìn)行時(shí)輸入版本參數(shù)。 //而執(zhí)行mvn -B release:prepare -X 則可以通過(guò)程序直接執(zhí)行。但是若要自定義版本信息則需要配置pom release plugin的參數(shù),或采用如下命令 //實(shí)際執(zhí)行的mvn命令. //mvn -B release:prepare -X -Dtag=VersionControlDemo-"0.4.0" -DreleaseVersion="0.4.0" -DdevelopmentVersion="0.4.1-SNAPSHOT" //mvn release:perform -X public static void main(String[] args) throws MavenInvocationException { InvocationRequest request = new DefaultInvocationRequest(); //獲取pom文件地址 String relativelyPath=System.getProperty("user.dir"); String pomPath = relativelyPath+"/pom.xml"; System.out.println(pomPath); request.setPomFile(new File(pomPath)); Invoker invoker = new DefaultInvoker(); //獲取maven環(huán)境變量地址 String m2Path = System.getenv("MAVEN_HOME"); System.out.println("m2Path:"+m2Path); invoker.setMavenHome(new File(m2Path)); try { //該版本tag信息 String tag = "VersiongControlDemo-0.4.0"; //此次發(fā)布的版本號(hào) String version = "0.4.0"; //下一次版本的快照版本號(hào) String developmentVersion="0.4.1-SNAPSHOT"; List<String> goals = new ArrayList<>(); goals.add("-B"); goals.add("release:prepare"); goals.add("-X"); goals.add("-Dtag=" + tag); goals.add("-DreleaseVersion=" + version); goals.add("-DdevelopmentVersion=" + developmentVersion); request.setGoals(goals); System.out.println("開(kāi)始: " + request.getGoals()); invoker.execute(request); request.setGoals(Collections.singletonList("release:perform -X")); System.out.println("開(kāi)始: " + request.getGoals()); invoker.execute(request); } catch (MavenInvocationException e) { e.printStackTrace(); return; } } }
運(yùn)行測(cè)試demo。結(jié)果成功。(每次運(yùn)行前都要注意版本參數(shù),切勿沖突。)
同理可配置release:rollback
等相關(guān)回滾命令。
到此這篇關(guān)于Springboot 整合maven插口調(diào)用maven release plugin。實(shí)現(xiàn)一鍵打包功能。的文章就介紹到這了,更多相關(guān)Springboot 整合maven 一鍵打包內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
java實(shí)現(xiàn)合并單元格的同時(shí)并導(dǎo)出excel示例
這篇文章主要給大家介紹了關(guān)于java實(shí)現(xiàn)合并單元格的同時(shí)并導(dǎo)出excel的相關(guān)資料,文中先進(jìn)行了簡(jiǎn)單的介紹,之后給出了詳細(xì)的示例代碼,相信對(duì)大家具有一定的參考價(jià)值,需要的朋友們下面來(lái)一起看看吧。2017-03-03淺析SpringBoot2.4 靜態(tài)資源加載問(wèn)題
這篇文章主要介紹了SpringBoot2.4 靜態(tài)資源加載問(wèn)題,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-01-01在Java 8中將List轉(zhuǎn)換為Map對(duì)象方法
這篇文章主要介紹了在Java 8中將List轉(zhuǎn)換為Map對(duì)象方法,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2018-11-11基于Spring Boot的Logback日志輪轉(zhuǎn)配置詳解
本篇文章主要介紹了基于Spring Boot的Logback日志輪轉(zhuǎn)配置詳解,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-10-10Java實(shí)現(xiàn)迅雷地址轉(zhuǎn)成普通地址實(shí)例代碼
本篇文章主要介紹了Java實(shí)現(xiàn)迅雷地址轉(zhuǎn)成普通地址實(shí)例代碼,非常具有實(shí)用價(jià)值,有興趣的可以了解一下。2017-03-03