Blog Infos
Author
Published
Topics
Published
Topics
fun BaseExtension.baseConfig() {
compileSdkVersion(AppConfig.compileSdk)
defaultConfig.apply {
minSdk = AppConfig.minSdk
targetSdk = AppConfig.targetSdk
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
compileOptions.apply {
sourceCompatibility = AppConfig.CompileOptions.javaSourceCompatibility
targetCompatibility = AppConfig.CompileOptions.javaSourceCompatibility
}
tasks.withType<KotlinCompile> {
kotlinOptions {
jvmTarget = AppConfig.CompileOptions.kotlinJvmTarget
}
}
}
view raw baseconfig.kts hosted with ❤ by GitHub

To apply these we need to add a second extension function:

/**
* Apply configuration settings that are shared across all modules.
*/
fun PluginContainer.applyBaseConfig(project: Project) {
whenPluginAdded {
when (this) {
is AppPlugin -> {
project.extensions
.getByType<AppExtension>()
.apply {
baseConfig()
}
}
is LibraryPlugin -> {
project.extensions
.getByType<LibraryExtension>()
.apply {
baseConfig()
}
}
}
}
}
subprojects {
project.plugins.applyBaseConfig(project)
}
view raw subprojects.kts hosted with ❤ by GitHub

Now your module-specific build files can look as simple as this

plugins {
id(Plugins.androidLibrary)
kotlin(Plugins.kotlinAndroid)
}
dependencies {
implementation(projects.core.logging)
implementation(Dependencies.hiltAndroid)
}

This article was originally published on proandroiddev.com on March 05, 2022

Job Offers

Job Offers

There are currently no vacancies.

OUR VIDEO RECOMMENDATION

,

Declarative Gradle on Android

Declarative Gradle is a project that targets better isolation of concern and expressing any build clearly and understandably. It is our key initiative towards improving the developer experience and maintainability of Gradle projects.
Watch Video

Declarative Gradle on Android

Nelson Osacky & Inaki Villar
Lead Solutions Engineer & solutions engineer
Gradle

Declarative Gradle on Android

Nelson Osacky & In ...
Lead Solutions Engin ...
Gradle

Declarative Gradle on Android

Nelson Osacky & ...
Lead Solutions Engineer & ...
Gradle

Jobs

No results found.

YOU MAY BE INTERESTED IN

YOU MAY BE INTERESTED IN

blog
Managing dependencies in a single module project is pretty simple, but when you start…
READ MORE
blog
Creating features in Android development often involves repetitive tasks like setting up screen files,…
READ MORE
blog

Running Instrumented Tests in a Gradle task

During the latest Google I/O, a lot of great new technologies were shown. The…
READ MORE
blog
Many of us have faced Groovy difficulties and used to convert it to Kotlin…
READ MORE
Menu