Created
July 20, 2019 17:48
-
-
Save pavlospt/3bd548e5c2daf927371172ffe29fc796 to your computer and use it in GitHub Desktop.
Root build.gradle.kts
This file contains 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
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