Create multiple jars, one for each environment(spring profile) using spring-boot


I want to have 3 tasks:


each of them will create jar file for specific spring-boot-profile.

buildLocal task will use
buildDev task will use
buildProd task will use

when running spring-boot app this are options to provide specific profile:

  1. Set parameter in
  2. WebApplicationInitializer
  3. JVM System parameter
  4. 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/')
      	def lines = file.readLines()
      	file.write "\n"
      	lines.each { line ->
      		file << line + "\n"

buildDev.dependsOn build

This almost works, jar file is how it should be, but the problem is, 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.