The KmpConfigurationPlugin
is a Gradle plugin designed to automatically configure Kotlin
Multiplatform (KMP) projects based on whether the project is an Android Application or an Android
Library. It simplifies the process of setting up dependencies and configurations for Android, Kotlin
Multiplatform, and Compose.
- Automatically configures the project based on the presence of the
com.android.application
orcom.android.library
plugin. - Can be applied after
com.android.application
orcom.android.library
plugins. - Simplifies the setup of Kotlin Multiplatform configurations for Android applications and libraries.
- Preconfigured dependencies for:
- Coroutines
- Compose
- Koin
- Ktor
- Room
- DataStore
- Lifecycle
- Coil
- Gradle 7.x or higher.
- Android Gradle Plugin 8.x or higher.
- Kotlin 1.6 or higher.
Add the following to your settings.gradle.kts
to ensure that the plugin is available:
pluginManagement {
repositories {
google()
mavenCentral()
}
}
In your build.gradle.kts
file, add the following plugin declarations:
plugins {
alias(libs.plugins.android.library) // For Android Library
alias(libs.plugins.kmp.configuration) // KMP Configuration Plugin
}
The KmpConfigurationPlugin
must be applied after either the com.android.library
or
com.android.application
plugin.
The plugin automatically configures your project based on the type of Android plugin you use. You can configure dependencies for Kotlin Coroutines, KotlinX, Lifecycle, and Compose Multiplatform.
plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.kmp.configuration) // Register KMP Configuration Plugin
}
kotlin {
with(
configuration = kmpConfiguration,
extension = this,
) { configuration, extension ->
// Configure dependencies for Kotlin Coroutines, KotlinX, and Lifecycle
configuration.coroutine.configureDependencies(extension)
configuration.kotlinX.configureDependencies(extension)
configuration.lifecycle.configureDependencies(extension)
}
}
plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.compose.compiler)
alias(libs.plugins.compose.multiplatform)
alias(libs.plugins.kmp.configuration) // Register KMP Configuration Plugin
}
kotlin {
with(
configuration = kmpConfiguration,
extension = this,
composeDependencies = compose
) { configuration, extension, composeDependencies ->
// Configure dependencies for Compose Multiplatform
configuration.coroutine.configureDependencies(extension)
configuration.compose.configureDependencies(extension, composeDependencies)
configuration.kotlinX.configureDependencies(extension)
configuration.lifecycle.configureDependencies(extension)
}
}
- Automatic Configuration: The plugin automatically detects whether the project is an Android application or an Android library and applies the appropriate configurations.
- Flexible Dependency Configuration: The plugin provides an easy way to configure dependencies for Kotlin Coroutines, KotlinX, Lifecycle, and Compose Multiplatform.
- Sequential Plugin Registration: The
kmp.configuration
plugin should always be registered after thecom.android.library
orcom.android.application
plugin, as shown in the examples above.
The plugin will configure the project based on the type of Android plugin (com.android.application
or com.android.library
) that is used. The configuration logic for both Android applications and
libraries is automatically applied.
configuration.coroutine.configureDependencies(extension)
- Configures dependencies for Kotlin Coroutines.configuration.kotlinX.configureDependencies(extension)
- Configures dependencies for KotlinX.configuration.lifecycle.configureDependencies(extension)
- Configures dependencies for Lifecycle.configuration.compose.configureDependencies(extension, composeDependencies)
- Configures dependencies for Compose Multiplatform (only for projects using Compose).
- Android Application: The plugin detects if the project is an Android application using the
com.android.application
plugin and applies theapplicationConfigurator
. - Android Library: The plugin detects if the project is an Android library using the
com.android.library
plugin and applies thelibraryConfigurator
.
This plugin is licensed under the MIT License. See the LICENSE file for more details.