I have a doNecessaryJob
task that depends on preProcessing
task. If a certain condition in preProcessing
is true, I want to stop the sync right away. How do I do that?
Part of my gradle is here:
task preProcessing() {
Gradle gradle = getGradle()
String tskReqStr = gradle.getStartParameter().getTaskRequests().toString()
Pattern pattern
if (tskReqStr.contains("assemble"))
pattern = Pattern.compile("assemble(\\w+)(Release|Debug)")
else
pattern = Pattern.compile("generate(\\w+)(Release|Debug)")
Matcher matcher = pattern.matcher(tskReqStr)
if (matcher.find()) {
// do processing here
} else {
println "Error, stopping the sync."
// !STOP THE GRADLE SYNC HERE DUE TO ERROR!
}
}
task doNecessaryJob() {
dependsOn preProcessing
// do necessary processing here that depends on variables from preProcessing task
}
I checked other solutions here in SO but all seem to point to the command line solution such as How to stop Gradle task execution in Android Studio?.