I\'m trying to set up gradle to launch the bootRun process with various spring profiles enabled.
My current bootRun configuration looks lik
Configuration for 4 different task with different profiles and gradle tasks dependencies:
bootRunLocal and bootRunDev - run with specific profilebootPostgresRunLocal and bootPostgresRunDev same as prev, but executing custom task runPostgresDocker and killPostgresDocker before/after bootRunbuild.gradle:
final LOCAL='local'
final DEV='dev'
void configBootTask(Task bootTask, String profile) {
bootTask.main = bootJar.mainClassName
bootTask.classpath = sourceSets.main.runtimeClasspath
bootTask.args = [ "--spring.profiles.active=$profile" ]
// systemProperty 'spring.profiles.active', profile // this approach also may be used
bootTask.environment = postgresLocalEnvironment
}
bootRun {
description "Run Spring boot application with \"$LOCAL\" profile"
doFirst() {
configBootTask(it, LOCAL)
}
}
task bootRunLocal(type: BootRun, dependsOn: 'classes') {
description "Alias to \":${bootRun.name}\" task: ${bootRun.description}"
doFirst() {
configBootTask(it, LOCAL)
}
}
task bootRunDev(type: BootRun, dependsOn: 'classes') {
description "Run Spring boot application with \"$DEV\" profile"
doFirst() {
configBootTask(it, DEV)
}
}
task bootPostgresRunLocal(type: BootRun) {
description "Run Spring boot application with \"$LOCAL\" profile and re-creating DB Postgres container"
dependsOn runPostgresDocker
finalizedBy killPostgresDocker
doFirst() {
configBootTask(it, LOCAL)
}
}
task bootPostgresRunDev(type: BootRun) {
description "Run Spring boot application with \"$DEV\" profile and re-creating DB Postgres container"
dependsOn runPostgresDocker
finalizedBy killPostgresDocker
doFirst() {
configBootTask(it, DEV)
}
}