[英]Spring Boot Maven Plugin: Exclude properties file from final jar
We have a Spring Boot application, and in it we have both an application.properties
and a application-dev.properties
. 我们有一个Spring Boot应用程序,其中有
application.properties
和application-dev.properties
。 The application properties file just has some across the board default values, and the application-dev properties has some really rudimentary credentials in it. 应用程序属性文件仅具有一些全面的默认值,而application-dev属性中具有一些真正的基础凭证。
When we deploy our jar, the application gets its properties from the environment its deployed to so, we don't utilize the profiles feature except when we want to develop locally against our 'dev' environment. 部署jar时,应用程序从部署环境中获取其属性,因此,除非要针对'dev'环境进行本地开发,否则我们不会利用配置文件功能。
Our secops department has told us that they no longer want us to include that dev properties file from the final jar that's deployed to production, but they have ok'd us leaving the file in version control so we can at least track changes and build/run locally. 我们的思科普斯科普斯部门告诉我们,他们不再希望我们从部署到生产中的最终jar中包含该dev属性文件,但是他们可以将文件留在版本控制中,以便我们至少可以跟踪更改和构建/在本地运行。
I've been reading through the spring-boot-maven-plugin configuration, and I can't see a way to just tell maven to exclude that file when building the final jar while still copying it into the target
directory so our team can still do their hacking locally. 我一直在阅读spring-boot-maven-plugin配置,但看不到一种方法可以告诉maven在构建最终jar时将文件排除在外,同时仍将其复制到
target
目录中,因此我们的团队仍然可以在本地进行黑客入侵。
I messed around with profiles for a bit, but I found that it was too confusing to explain to others and became a little cumbersome as additional permutations of scenarios came about. 我把配置文件弄乱了一些,但是我发现它太混乱了,无法向其他人解释,并且随着场景的其他排列的出现变得有点麻烦。
Ultimately the simplest thing is to configure the jar plugin to exclude the file. 最终,最简单的事情是配置jar插件以排除该文件。 Here is a snippet from our pom.
这是我们pom的片段。
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<excludes>
<!-- This is where the exclusion occurs -->
<exclude>**/application-*.properties</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.