Niko
Niko

Reputation: 4468

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. The application properties file just has some across the board default values, and the application-dev properties has some really rudimentary credentials in it.

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.

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.

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.

Upvotes: 7

Views: 12640

Answers (1)

Niko
Niko

Reputation: 4468

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. Here is a snippet from our 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>

Upvotes: 17

Related Questions