利用Maven添加工程版本信息及時間戳
更新時間:2021年12月30日 10:36:31 作者:天空win
這篇文章主要介紹了利用Maven添加工程版本信息及時間戳方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
Maven添加工程版本信息及時間戳
定義全局變量
pom文件中添加
<properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.build.number>1.0.5</maven.build.number> <maven.build.timestamp.format>yyyy-MM-dd HH:mm:ss</maven.build.timestamp.format> </properties>
給MANIFEST.MF文件添加版本及時間戳信息
pom文件中添加
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <configuration> <!-- 如果是jar包值為true,如果是war包值為false --> <archiveClasses>false</archiveClasses> <archive> <manifest> <addDefaultImplementationEntries>true</addDefaultImplementationEntries> <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries> </manifest> <manifestEntries> <Build-Number>${maven.build.number}</Build-Number> <Timestamp>${maven.build.timestamp}</Timestamp> </manifestEntries> </archive> </configuration> </plugin>
Maven版本發(fā)布添加上時間戳
使用插件添加時間戳
我使用的是spring boot - 2.0.3.RELEASE版本
pom中加入
<!-- 加入這個 就可以直接在配置文件中取到時間戳了,注意: 由于${}方式會被maven處理。 如果你pom繼承了spring-boot-starter-parent, Spring Boot已經(jīng)將maven-resources-plugins默認的${}方式改為了@@方式,例如:@timestamp@ --> <properties> <project.build.version>@timestamp@</project.build.version> </properties> <build> <finalName>${artifactId}_${timestamp}</finalName> <plugins> ..... <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>buildnumber-maven-plugin</artifactId> <version>1.4</version> <configuration> <timestampFormat>yyyyMMddHHmmss</timestampFormat> </configuration> <executions> <execution> <goals> <goal>create-timestamp</goal> </goals> </execution> </executions> <inherited>false</inherited> </plugin> </plugins> ..... </build>
現(xiàn)在只需要在配置文件加入(用的的是.yml)
project: build: version: @project.build.version@<br><br>如果是.properties文件 project.build.version= @project.build.version@
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
JAVA HashSet和TreeSet 保證存入元素不會重復的操作
這篇文章主要介紹了JAVA HashSet和TreeSet 保證存入元素不會重復的操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-09-09