[TOC]
war方式
- 下添加属性
<properties>
<!-- maven.build.timestamp 默认时间戳格式 -->
<maven.build.timestamp.format>yyyyMMddHHmmss</maven.build.timestamp.format>
</properties>
- pom.xml
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<useCache>true</useCache>
</configuration>
<executions>
<execution>
<id>prepare-war</id>
<phase>prepare-package</phase>
<goals>
<goal>exploded</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<executions>
<!-- 打包前进行替换 -->
<execution>
<phase>prepare-package</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- 自动识别到项目target文件夹 -->
<basedir>${project.build.directory}</basedir>
<!-- 替换的文件所在目录规则 -->
<includes>
<include>${project.build.finalName}/index.html</include>
<!-- <include>${project.build.finalName}/WEB-INF/**/*.html</include>-->
</includes>
<replacements>
<!-- 更改规则,在css/js文件末尾追加?v=时间戳,反斜杠表示字符转义 -->
<replacement>
<token>\.css\"</token>
<value>.css?v=${project.version}-${maven.build.timestamp}\"</value>
</replacement>
<replacement>
<token>\.css\'</token>
<value>.css?v=${project.version}-${maven.build.timestamp}\'</value>
</replacement>
<replacement>
<token>\.js\"</token>
<value>.js?v=${project.version}-${maven.build.timestamp}\"</value>
</replacement>
<replacement>
<token>\.js\'</token>
<value>.js?v=${project.version}-${maven.build.timestamp}\'</value>
</replacement>
</replacements>
</configuration>
</plugin>
</plugins>
</build>
springboot jar方式
- 下添加属性
<properties>
<!-- maven.build.timestamp 默认时间戳格式 -->
<maven.build.timestamp.format>yyyyMMddHHmmss</maven.build.timestamp.format>
</properties>
- 包含前端页面的项目添加plugin插件
<build>
<plugins>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<executions>
<!-- 打包前进行替换 -->
<execution>
<phase>prepare-package</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- 自动识别到项目target文件夹 -->
<basedir>${project.build.directory}</basedir>
<!-- 注意事项,一定不能写错 -->
<includes>
<include>classes/static/index.html</include>
</includes>
<replacements>
<!-- 更改规则,在css/js文件末尾追加?v=时间戳,反斜杠表示字符转义 -->
<replacement>
<token>\.css\"</token>
<value>.css?v=${project.version}-${maven.build.timestamp}\"</value>
</replacement>
<replacement>
<token>\.css\'</token>
<value>.css?v=${project.version}-${maven.build.timestamp}\'</value>
</replacement>
<replacement>
<token>\.js\"</token>
<value>.js?v=${project.version}-${maven.build.timestamp}\"</value>
</replacement>
<replacement>
<token>\.js\'</token>
<value>.js?v=${project.version}-${maven.build.timestamp}\'</value>
</replacement>
</replacements>
</configuration>
</plugin>
</build>