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

时间:2022-07-17 02:20:42

一、定义全局变量

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>