简体   繁体   English

Spring Boot Maven插件:从最终的jar中排除属性文件

[英]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.propertiesapplication-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.

相关问题 Maven Maven-assembly-plugin jar-with-dependencies从最终jar中排除LICENSE.txt - Maven maven-assembly-plugin jar-with-dependencies exclude LICENSE.txt from final jar 使用 Spring Boot Maven 插件时,jar 文件中缺少 Spring Boot 应用程序中的资源 - resources in a Spring Boot application are missing from jar file when using Spring Boot Maven Plugin 使用spring boot和spring-boot-maven-plugin生成war时排除application.properties - Exclude application.properties when generating war using spring boot and spring-boot-maven-plugin Spring Boot Maven 插件 – 排除所有依赖 - Spring Boot Maven Plugin – Exclude all dependencies 如何从spring boot jar中排除资源文件? - How to exclude resource file from spring boot jar? Gradle 构建:从 Spring 引导文件中排除资源文件 Jar 文件 - Gradle build: Exclude resources files from Spring Boot Jar file Spring Boot Maven 插件 - 重命名原始 JAR - Spring Boot Maven Plugin - rename original JAR 同时使用Maven Jar插件和Spring引导maven插件 - Use Maven Jar plugin and Spring boot maven plugin simultaneously 如何排除默认的application.properties在Spring启动项目的Maven中使用配置文件添加自定义属性文件? - How to exclude default application.properties add custom properties file using profiles in maven for spring boot project? Spring 启动 maven 构建不包括最终 jar 中的工件版本 - Spring boot maven build not including artifact version in final jar
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM