The easiest way is to define a default value and allow it to be overridden. I am not sure what the use of systemProperty is 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 to your task, you can do something like this:
task setDevProperties(dependsOn: bootRun) << { doFirst { System.setProperty('spring.profiles.active', profiles) } }
Gradle has many ways to achieve this.
Edit:
Configure separate configuration files for each 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 the prod flag in this case like this:
./gradlew <task> -Pprod
source share