I have defined few custom build tasks, which set few configuration properties and generate builds for different environments. Tasks are below:
val buildStage by tasks.registering {
doFirst {
val profile = "stage"
println("spring.profiles.active = $profile")
System.setProperty("spring.profiles.active", profile)
buildDir = File("${rootDir}/build/${profile}")
tasks.withType<ProcessResources> {
exclude("**/*.properties")
}
}
finalizedBy(tasks.getByName("build"))
}
val buildProd by tasks.registering {
doFirst {
val profile = "prod"
println("spring.profiles.active = $profile")
System.setProperty("spring.profiles.active", profile)
buildDir = File("${rootDir}/build/${profile}")
tasks.withType<ProcessResources> {
exclude("**/*.properties")
}
}
finalizedBy(tasks.getByName("build"))
}
How can I ensure that gradle build
command is not directly invokable?
Is it possible to do something like:
tasks.getByName("build") {
doFirst {
if (System.getProperty("spring.profiles.active").isNullOrBlank()) {
println("task not allowed")
exitProcess(1)
}
}
}