时间:2023-02-15 13:14:59 | 栏目:JAVA代码 | 点击:次
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>
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>
我使用的是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>
project: build: version: @project.build.version@<br><br>如果是.properties文件 project.build.version= @project.build.version@