Skip to content

Instantly share code, notes, and snippets.

@sandipchitale
Last active November 18, 2020 22:41
Show Gist options
  • Save sandipchitale/cbea58c7eacfc91d1ab19dc3ab143b5f to your computer and use it in GitHub Desktop.
Save sandipchitale/cbea58c7eacfc91d1ab19dc3ab143b5f to your computer and use it in GitHub Desktop.
Simple recipe based execution of tasks
// Apply using the following at the end of build.gradle
//
// if (hasProperty('RECIPE')) {
// apply from: 'recipe.gradle'
// }
//
// Usage:
//
// > .\gradlew.bat -PRECIPE=First
//
def RECIPE_MAP = [:]
RECIPE_MAP[':app:compileJava'] = ['+', '-', '-',]
RECIPE_MAP[':app:processResources'] = ['+', '-', '-',]
RECIPE_MAP[':app:classes'] = ['+', '-', '-',]
RECIPE_MAP[':app:jar'] = ['+', '+', '+',]
RECIPE_MAP[':app:startScripts'] = ['-', '-', '-',]
RECIPE_MAP[':app:distTar'] = ['-', '-', '-',]
RECIPE_MAP[':app:distZip'] = ['-', '-', '-',]
RECIPE_MAP[':app:assemble'] = ['-', '-', '-',]
RECIPE_MAP[':app:compileTestJava'] = ['+', '+', '+',]
RECIPE_MAP[':app:processTestResources'] = ['+', '+', '+',]
RECIPE_MAP[':app:testClasses'] = ['+', '+', '+',]
RECIPE_MAP[':app:test'] = ['+', '+', '+',]
RECIPE_MAP[':app:check'] = [' ', ' ', ' ',]
RECIPE_MAP[':app:build'] = [' ', ' ', ' ',]
enum RECIPES { // | | |
FIRST, // -------------------------+ | |
SECOND, // ------------------------------+ |
THIRD, // -----------------------------------+
}
if (hasProperty('RECIPE')) {
def recipeIndex = RECIPES.valueOf(RECIPE).ordinal()
def excludedTaskNames = []
def taskNames = []
RECIPE_MAP.each { entry ->
def recipe = entry.value
if (recipe[recipeIndex] == ' ') {
} else if (recipe[recipeIndex] == '-') {
excludedTaskNames += entry.key
} else if (recipe[recipeIndex] == '+') {
taskNames += entry.key
}
}
gradle.startParameter.excludedTaskNames = excludedTaskNames
gradle.startParameter.taskNames = taskNames
print "> gradlew ..."
gradle.startParameter.excludedTaskNames.each {
print " -x ${it} "
}
gradle.startParameter.taskNames.each {
print " ${it} "
}
println " ..."
gradle.taskGraph.beforeTask {
println "----------------------------------- ${it.path}"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment