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 Developer

    SumUp
    Berlin
    • Full Time
    apply now

    Senior Android Engineer

    Carly Solutions GmbH
    Munich
    • Full Time
    apply now

OUR VIDEO RECOMMENDATION

, , ,

Ultimate Iteration Speeds with Gradle Configuration Cache

A dive into what is Gradle Configuration Cache and how it works, why you want to have it enabled, and how to debug unexpected configuration cache misses for local and CI workflows.
Watch Video

Ultimate Iteration Speeds with Gradle Configuration Cache

Aurimas Liutikas
Software Engineer
Google / Gradle Fellow

Ultimate Iteration Speeds with Gradle Configuration Cache

Aurimas Liutikas
Software Engineer
Google / Gradle Fell ...

Ultimate Iteration Speeds with Gradle Configuration Cache

Aurimas Liutikas
Software Engineer
Google / Gradle Fellow

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
Many of us have faced Groovy difficulties and used to convert it to Kotlin…
READ MORE
blog
Recently, I needed to upgrade a dependency to a beta version (androidx.navigation:navigation-compose, version 2.8.0-beta02…
READ MORE

Leave a Reply

Your email address will not be published. Required fields are marked *

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

Menu