Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jrvansuita/c154488ace77b63af9367b74a42256d1 to your computer and use it in GitHub Desktop.
Save jrvansuita/c154488ace77b63af9367b74a42256d1 to your computer and use it in GitHub Desktop.
Getting the current buildtype and Flavor by assemble task using gradle scripts
gradle.allprojects {
ext.getCurrentProductVariant = {
def taskName = project.gradle.startParameter.taskNames.find { it.contains("assemble") }
if (taskName != null) {
def variantParts = taskName.split(/(?<!^)(?=[A-Z])/)[-2..-1].collect { it.toLowerCase() }
return new ProductVariant(buildType: variantParts[1], productFlavor: variantParts[0])
}
return null
}
}
class ProductVariant {
String buildType
String productFlavor
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment