0

I have SpringBoot project that generates both a deployable and an executable WAR file using the SpringBoot Gradle plugin. I want to update a .properties file inside of both WAR files. My files look like this:

build/libs/my-app-1.0.0.war
  ...
  /WEB-INF/classes/file.properties
  ...

build/libs/my-app-1.0.0-boot.war
  ...
  /WEB-INF/classes/file.properties
  ...

I want to update a single key inside the properties file or completely replace the file. Either solution would work.

These are the versions:

  • Gradle 6.2.2
  • SpringBoot 2.2.5.RELEASE
Elliot Vargas
  • 20,499
  • 11
  • 34
  • 36
  • 1
    This is called resource filtering, https://stackoverflow.com/questions/25328132/is-resource-filtering-in-gradle-possible-without-using-tokens – Lesiak Mar 23 '20 at 22:52

1 Answers1

0

I was able to solve the problem by modifying the answer linked by @Lesiak in the comments as follows:

processResources {
    filesMatching('**/file.properties') {
        filter(org.apache.tools.ant.filters.ReplaceTokens,
                tokens: [replace-token: project.property('replace-value').toString()])
    }
}
Elliot Vargas
  • 20,499
  • 11
  • 34
  • 36