Simplest way would be to define default and allow it to be overridden. I am not sure what is the use of systemProperty in this case. Simple arguments will do the job.
def profiles = 'prod'
bootRun {
args = ["--spring.profiles.active=" + profiles]
}
To run dev:
./gradlew bootRun -Pdev
To add dependencies on your task you can do something like this:
task setDevProperties(dependsOn: bootRun) << {
doFirst {
System.setProperty('spring.profiles.active', profiles)
}
}
There are lots of ways achieving this in Gradle.
Edit:
Configure separate configuration files per environment.
if (project.hasProperty('prod')) {
apply from: 'gradle/profile_prod.gradle'
} else {
apply from: 'gradle/profile_dev.gradle'
}
Each configuration can override tasks for example:
def profiles = 'prod'
bootRun {
systemProperty "spring.profiles.active", activeProfile
}
Run by providing prod
flag in this case just like that:
./gradlew <task> -Pprod