利用Maven添加工程版本信息及时间戳

目录Maven添加工程版本信息及时间戳定义全局变量给MANIFEST.MF文件添加版本及时间戳信息Maven版本发布添加上时间戳使用插件添加时间戳现在只需要在配置文件加入(用的的是.yml)

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版本发布添加上时间戳

使用插件添加时间戳

我使用的是spring boot – 2.0.3.RELEASE版本

pom中加入

<!--加入这个 就可以直接在配置文件中取到时间戳了,注意:由于${}方式会被maven处理。如果你pom继承了spring-boot-starter-parent,Spring Boot已经将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>

  

现在只需要在配置文件加入(用的的是.yml)

project:    build:      version: @project.build.version@<br><br>如果是.properties文件project.build.version= @project.build.version@

以上为个人经验,希望能给大家一个参考,也希望大家多多支持。

明天的希望,让我们忘了今天的痛苦

利用Maven添加工程版本信息及时间戳

相关文章:

你感兴趣的文章:

标签云: