Get the App
SLTechnology News&Howtos  ›  Development  › 

Springboot how to integrate maven socket and call maven release plugin to realize one-click Packaging function

Shulou Source: shulou.com Published: 2022-06-01 05:44:09 11月15日 Update

Editor to share with you how Springboot integrates the maven socket to call maven release plugin to achieve one-click packaging function. I hope you will get something after reading this article. Let's discuss it together.

Maven release plugin configuration integrates maven-invoker to enable the program to execute the mvn command 1. Guide package org.apache.maven.shared maven-invoker 3.1.0

Note the maven-invoker version. A lower version may result in incompatibility.

two。 The test program public class MavenTest {/ / Direct execution mvn release:prepare-X is interactive and cannot enter version parameters while the program is in progress. / / while executing mvn-B release:prepare-X can be executed directly through the program. However, to customize the version information, you need to configure the parameters of pom release plugin, or use the following command / / actually executed mvn command. / / 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 (); / / obtain pom file address String relativelyPath=System.getProperty ("user.dir"); String pomPath = relativelyPath+ "/ pom.xml" System.out.println (pomPath); request.setPomFile (new File (pomPath)); Invoker invoker = new DefaultInvoker (); / / get the maven environment variable address String m2Path = System.getenv ("MAVEN_HOME"); System.out.println ("m2Path:" + m2Path); invoker.setMavenHome (new File (m2Path)) Try {/ / tag information of this version String tag = "VersiongControlDemo-0.4.0"; / / the version number of this release is String version = "0.4.0"; / / the snapshot version number of the next version is String developmentVersion= "0.4.1-SNAPSHOT"; List 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 ("start:" + request.getGoals ()); invoker.execute (request); request.setGoals (Collections.singletonList ("release:perform-X")); System.out.println ("start:" + request.getGoals ()); invoker.execute (request);} catch (MavenInvocationException e) {e.printStackTrace () Return;}

Run the test demo. It turned out to be a success. Pay attention to the version parameters before each run, and do not conflict. )

Similarly, release:rollback and other related rollback commands can be configured.

After reading this article, I believe you have a certain understanding of "how Springboot integrates maven sockets to call maven release plugin to achieve one-click packaging function". If you want to know more about it, welcome to follow the industry information channel, thank you for reading!

Tags: Version command program integration parameter configuration function socket one button message address article test run success interactive variable can be passed finished actual Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Shulou Information vpn Linux MariaDB