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


    Senior Android Engineer

    Busuu
    Madrid
    • Full Time
    apply now

    Android Engineer

    ASOS
    London
    • Full Time
    apply now

    Android Manager (all genders)

    Babbel
    Berlin
    • Full Time
    apply now
Load more listings

OUR VIDEO RECOMMENDATION

,

Android Developer Productivity

Nelson has seen hundreds of Android teams around the world. This session covers some of the best tips from Gradle experts, how we investigate performance improvements and what is coming next from Gradle and Gradle…
Watch Video

Android Developer Productivity

Nelson Osacky
Solutions Engineer
Gradle

Android Developer Productivity

Nelson Osacky
Solutions Engineer
Gradle

Android Developer Productivity

Nelson Osacky
Solutions Engineer
Gradle

Jobs

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

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
Mobile device concept is one step ahead of the trend in technology, bringing an…
READ MORE
blog
According to the Gradle documentation dependency resolution is a process that consists of two…
READ MORE

Leave a Reply

Your email address will not be published.

Fill out this field
Fill out this field
Please enter a valid email address.

Menu