In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces the maven configuration file pom how to add variables to take the version number, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
Maven configuration file pom adds variable version number 1. Define the version number 3.2.2.RELEASE 2. Take the version number to facilitate the future shelf package version upgrade org.springframework spring-core ${spring.version} maven to read the program version number of three methods 1
In an application project, if the application needs to obtain the version number of the current program, you can read "/ META-INF/maven/$ {groupId} / ${artifactId} / pom.properties" to get the version information generated by maven.
Of course, the premise is that the application needs to know its own groupId and artifactId at run time, otherwise the path cannot be located.
Example of pom.properties content
# Created by Apache Maven .5.0version = 1.0.4-SNAPSHOTgroupId=com.gitee.l0kmartifactId=facelog-service
This approach is simple, but it also has drawbacks:
It seems that this method can only get ${project.version}, the default definition of maven, and cannot add custom information.
Method 2
Another option is to write version information directly to MANIFEST.MF. Read the parsing MANIFEST.MF through java.util.jar.Manifest to get the version number.
Add the buildnumber-maven-plugin plug-in as follows, and specify the parameters to write to MANIFEST.MF for the maven-jar-plugin plug-in.
Org.codehaus.mojo buildnumber-maven-plugin 1.2 create org.apache.maven.plugins maven-jar-plugin 3.0.2 ${project.version} ${buildNumber} ${maven.build.timestamp} method 3
For the first two scenarios, you need to package the application into a jar package to read the version information.
Then when the program is developed and debugged, it does not generate pom.properties, and MANIFEST.MF, so it cannot read the version information.
So another idea is to use the template-maven-plugin plug-in to have maven automatically generate a code that contains version information, such as Version.java. In this way, at any time, the program can easily know its own version number.
Template
First, you need a code template Version.java. The example is as follows:
Package net.gdface.facelog.service;public final class Version {/ * * project version * / public static final String VERSION = "${project.version}"; / * * SCM (git) revision * / public static final String SCM_REVISION= "${buildNumber}"; / * * SCM branch * / public static final String SCM_BRANCH = "${scmBranch}"; / * buildtimestamp * / public static final String TIMESTAMP = "${buildtimestamp}";}
The template is placed under / src/main/java/java-templates/$ {package_of_template} /
Originally in the template file with the maven built-in variable ${maven.build.timestamp} to do the timestamp, the actual run has not been correctly replaced, I do not know why. So use the timestamp generated by the buildnumber-maven-plugin plug-in (goal create-timestamp) ${buildtimestamp} instead
Plug-in
Then modify pom.xml to add template-maven-plugin plug-in and buildnumber-maven-plugin plug-in
Org.codehaus.mojo buildnumber-maven-plugin 1.4 bn1 create bn2 create-timestamp Buildtimestamp yyyy-MM-dd HH:mm:ss org.codehaus.mojo templating-maven-plugin 1.0.0 filter-src filter-sources
The template-maven-plugin plug-in replaces the ${xxx} placeholders in all templates under the / src/main/java/java-templates/ folder with variables of the same name in maven.
The generated Version.java is under ${project.build.directory} / generated-sources/$ {package_of_template}, and the folder automatically becomes the source folder to join the compilation process.
Thank you for reading this article carefully. I hope the article "how to increase the variable version number of maven configuration file pom" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.