Skip to content

Instantly share code, notes, and snippets.

@andhikayuana
Forked from PaoloMilano/PluginExtensions.kt
Created December 14, 2021 10:42
Show Gist options
  • Save andhikayuana/9ed8fc9edf5db167ffa770a72a507417 to your computer and use it in GitHub Desktop.
Save andhikayuana/9ed8fc9edf5db167ffa770a72a507417 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