Skip to content

Instantly share code, notes, and snippets.

@pavlospt
Created July 20, 2019 17:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pavlospt/3bd548e5c2daf927371172ffe29fc796 to your computer and use it in GitHub Desktop.
Save pavlospt/3bd548e5c2daf927371172ffe29fc796 to your computer and use it in GitHub Desktop.
Root build.gradle.kts
subprojects {
// Accessing the `PluginContainer` in order to use `whenPluginAdded` function
project.plugins.configure(project = project)
}
// Extension function on `PluginContainer`
fun PluginContainer.configure(project: Project) {
whenPluginAdded {
when (this) {
is AppPlugin -> {
project.extensions
.getByType<AppExtension>()
.apply {
applyCommons()
}
}
is LibraryPlugin -> {
project.extensions
.getByType<LibraryExtension>()
.apply {
applyCommons()
}
}
}
}
}
// Extension function on `AppExtension`
fun AppExtension.applyCommons() {
compileSdkVersion(Versions.COMPILE_SDK_VERSION)
defaultConfig.apply {
minSdkVersion(Versions.MIN_SDK_VERSION)
targetSdkVersion(Versions.TARGET_SDK_VERSION)
versionCode = Versions.APP_VERSION_CODE
versionName = Versions.APP_VERSION_NAME
}
compileOptions.apply {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}
// Extension function on `LibraryExtension`
fun LibraryExtension.applyCommons() {
compileSdkVersion(Versions.COMPILE_SDK_VERSION)
defaultConfig.apply {
minSdkVersion(Versions.MIN_SDK_VERSION)
targetSdkVersion(Versions.TARGET_SDK_VERSION)
}
compileOptions.apply {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment