Springboot?整合maven插口調(diào)用maven?release?plugin實現(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版本。版本過低可能導(dǎo)致不兼容。
2.測試程序
public class MavenTest { //直接執(zhí)行mvn release:prepare -X 為交互式執(zhí)行,無法在程序進行時輸入版本參數(shù)。 //而執(zhí)行mvn -B release:prepare -X 則可以通過程序直接執(zhí)行。但是若要自定義版本信息則需要配置pom release plugin的參數(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ā)布的版本號 String version = "0.4.0"; //下一次版本的快照版本號 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("開始: " + request.getGoals()); invoker.execute(request); request.setGoals(Collections.singletonList("release:perform -X")); System.out.println("開始: " + request.getGoals()); invoker.execute(request); } catch (MavenInvocationException e) { e.printStackTrace(); return; } } }
運行測試demo。結(jié)果成功。(每次運行前都要注意版本參數(shù),切勿沖突。)
同理可配置release:rollback
等相關(guān)回滾命令。
到此這篇關(guān)于Springboot 整合maven插口調(diào)用maven release plugin。實現(xiàn)一鍵打包功能。的文章就介紹到這了,更多相關(guān)Springboot 整合maven 一鍵打包內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
java實現(xiàn)合并單元格的同時并導(dǎo)出excel示例
這篇文章主要給大家介紹了關(guān)于java實現(xiàn)合并單元格的同時并導(dǎo)出excel的相關(guān)資料,文中先進行了簡單的介紹,之后給出了詳細的示例代碼,相信對大家具有一定的參考價值,需要的朋友們下面來一起看看吧。2017-03-03在Java 8中將List轉(zhuǎn)換為Map對象方法
這篇文章主要介紹了在Java 8中將List轉(zhuǎn)換為Map對象方法,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下2018-11-11基于Spring Boot的Logback日志輪轉(zhuǎn)配置詳解
本篇文章主要介紹了基于Spring Boot的Logback日志輪轉(zhuǎn)配置詳解,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-10-10Java實現(xiàn)迅雷地址轉(zhuǎn)成普通地址實例代碼
本篇文章主要介紹了Java實現(xiàn)迅雷地址轉(zhuǎn)成普通地址實例代碼,非常具有實用價值,有興趣的可以了解一下。2017-03-03