Hi,
I want to have 3 tasks:
buildLocal
buildDev
buildProd
each of them will create jar file for specific spring-boot-profile.
i.g.
buildLocal task will use application.properties
buildDev task will use application-dev.properties
buildProd task will use application-prod.properties
when running spring-boot app this are options to provide specific profile:
- Set spring.profiles.active parameter in application.properties
- WebApplicationInitializer
- JVM System parameter
- Environment variable
I want to use 1. option because that way I will have jar which knows which profile is activated.
I tried something like this:
task buildDev { doLast { def file = file('src/main/resources/application.properties') def lines = file.readLines() lines.remove(0) file.write "spring.profiles.active=dev\n" lines.each { line -> file << line + "\n" } } }
buildDev.dependsOn build
This almost works, jar file is how it should be, but the problem is, application.properties in a project is changed too, which I don’t want, it should be same as before launching buildDev task.
I will appreciate any help here, thank you.