Created
July 11, 2023 01:29
-
-
Save jrvansuita/c154488ace77b63af9367b74a42256d1 to your computer and use it in GitHub Desktop.
Getting the current buildtype and Flavor by assemble task using gradle scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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