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 Software Engineer (f/m/d)

    Paradox Cat GmbH
    Munich
    • Full Time
    apply now

    Android Test Automation Engineer

    Komoot
    Remote
    • Full Time
    apply now

    Android Software Engineer (f/m/d)

    Paradox Cat GmbH
    Munich
    • Full Time
    apply now

OUR VIDEO RECOMMENDATION

,

Plugging Into the Gradle Matrix

Whether consolidating build script logic, writing convention plugins, or adding tooling to your apps, Gradle plugins are powerful ways to extend your build.
Watch Video

Plugging Into the Gradle Matrix

John Rodriguez & Tony Robalik
Android engineer & Senior software person
Android & Square

Plugging Into the Gradle Matrix

John Rodriguez & T ...
Android engineer & ...
Android & Square

Plugging Into the Gradle Matrix

John Rodriguez & ...
Android engineer & Senio ...
Android & Square

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. Required fields are marked *

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

Menu