Skip to content

Instantly share code, notes, and snippets.

@PaoloMilano
Last active December 14, 2021 10:42
Show Gist options
  • Save PaoloMilano/e35a9609ed503d90d3e2178fbcfa2801 to your computer and use it in GitHub Desktop.
Save PaoloMilano/e35a9609ed503d90d3e2178fbcfa2801 to your computer and use it in GitHub Desktop.
fun Project.android(): BaseExtension {
val android = project.extensions.findByType(BaseExtension::class.java)
if (android != null) {
return android
} else {
throw GradleException("Project $name is not an Android project")
}
}
fun BaseExtension.variants(): DomainObjectSet<out BaseVariant> {
return when (this) {
is AppExtension -> {
applicationVariants
}
is FeatureExtension ->{
featureVariants
}
is LibraryExtension -> {
libraryVariants
}
else -> throw GradleException("Unsupported BaseExtension type!")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment