我们在打包时
通常会加上目标环境,即${spring.profiles.active}
亦或者加上端口号,即${server.port}
亦或者想知道打包的文件日期,即timestamp
想要实现需要,大多是通过build中的plugin去实现
读取properties文件
<build><finalName>${artifactId}_${version}_${server.port}_${spring.profiles.active}</finalName><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin><!-- 保证application.properties中的变量能够在maven中读取,用${xx}占位替换 --><plugin><groupId>org.codehaus.mojo</groupId><artifactId>properties-maven-plugin</artifactId><version>1.0.0</version><executions><execution><phase>initialize</phase><goals><goal>read-project-properties</goal></goals><configuration><files><file>src/main/resources/application.properties</file></files></configuration></execution></executions></plugin></plugins></build>
读取yml文件
项目地址:https://github.com/ozimov/yaml-properties-maven-plugin
在项目中也给出了使用姿势
<build><finalName>${artifactId}_${version}_${server.port}_${spring.profiles.active}</finalName><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin><!-- 保证application.yml中的变量能够在maven中读取,用${xx}占位替换 --><plugin><groupId>it.ozimov</groupId><artifactId>yaml-properties-maven-plugin</artifactId><version>1.1.3</version><executions><execution><phase>initialize</phase><goals><goal>read-project-properties</goal></goals><configuration><files><file>src/main/resources/application.yml</file></files></configuration></execution></executions></plugin></plugins></build>
spring-boot-maven-plugin 版本为2.1.2 下有效, 2.1.4下无效
添加timestamp
<build><finalName>${artifactId}_${version}_${timestamp}</finalName><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin><plugin><groupId>org.codehaus.mojo</groupId><artifactId>buildnumber-maven-plugin</artifactId><version>1.4</version><configuration><!-- 这里指定timestamp的格式 --><timestampFormat>yyyyMMdd_HHmm</timestampFormat></configuration><executions><execution><goals><goal>create-timestamp</goal></goals></execution></executions><inherited>false</inherited></plugin></plugins></build>