A collection of convention plugins to consistently configure Android applications and libraries. The plugins require Gradle 8.4+ and Android Gradle Plugin 8.3+ for Android projects.
All plugins are published to Maven Central. To use the plugins add the following repository to settings.gradle.kts
under pluginManagement
:
pluginManagement {
repositories {
mavenCentral()
}
}
When using the convention plugins certain versions are expected to be in the version catalog of the project. The version catalog named libs
is used by default but the catalog can be changed by setting the kgp.versioncatalog.name
property in the gradle.properties
file of the root project.
The following versions are required in the version catalog:
- kgpJdk: The JDK version to use when setting
jvmToolchain
.
The following versions are required in the version catalog when using Android convention plugins:
- kgpCompileSdk: The SDK version the application compiles against.
- kgpMinSdk: The minimum API level required to run the application.
- kgpTargetSdk: The API level the application targets.
- kgpDokka: The version used for the Android Documentation Plugin dependency.
Some convention plugins auto-apply other plugins to better support common use cases. However, it is possible the plugins are not wanted on certain projects. When present in the gradle.properties
file, the properties below can be used to prevent plugins from being auto-applied on supported projects:
kgp.plugins.autoapply.dependencymanagement=false
kgp.plugins.autoapply.dokka=false
kgp.plugins.autoapply.kotlinter=false
kgp.plugins.autoapply.kover=false
A plugin that only gets applied to the root project in a multi-project build. It applies common configuration to the root project and subprojects including:
- Creating a clean task to delete the build directory of the root project.
- Setting the following default values for subprojects when enabled with
kgp.autoconfigure.publishingproperties
:- group:
com.kroger.{rootProject.name}
- version: set to the value of the environment variable
BUILD_VERSION
if it exists, otherwise0.0.1
- group:
- Configures the Kotlinter plugin.
- Configures the Dependency Management plugin.
Add the following plugin to the root project build.gradle.kts
file:
plugins {
alias(libs.plugins.conventions.rootPlugin)
}
- Applies common configuration to Android applications such as
defaultConfig
,compileOptions
, andpackaging
- Also applies and configures the following plugins:
- Android Application
- Kotlin Android
- Kover
- See Compose Configuration for more information on how Jetpack Compose is configured
Add the following plugin to the build.gradle.kts
file of the Android application:
plugins {
alias(libs.plugins.conventions.androidApplication)
}
- Applies common configuration to Android libraries such as
defaultConfig
,compileOptions
,packaging
, and creating a sources jar. - Also applies and configures the following plugins:
- Release Conventions
- Android Library
- Kotlin Android
- Kover
- Dokka
- android-junit5
- See Compose Configuration for more information on how Jetpack Compose is configured
Add the following plugin to the build.gradle.kts
file of the Android library:
plugins {
alias(libs.plugins.conventions.publishedAndroidLibrary)
}
Alternatively if the library does not need to be published the following plugin can be used instead:
plugins {
alias(libs.plugins.conventions.androidLibrary)
}
- Applies common configuration to Kotlin libraries such as creating a sources jar and configuring junit5 testing.
- Also applies and configures the following plugins:
Add the following plugin to the build.gradle.kts
file of the Kotlin library:
plugins {
alias(libs.plugins.conventions.publishedKotlinLibrary)
}
Alternatively if the library does not need to be published the following plugin can be used instead:
plugins {
alias(libs.plugins.conventions.KotlinLibrary)
}
This plugin is automatically applied when using either the Published Android Library Plugin or the Published Kotlin Library plugin. It uses the Gradle Maven Publish Plugin to publish the aar artifact for Android libraries or jar artifact for Kotlin libraries, including the sources jar when available, to the repository specified by the kgp.repository.url
gradle property. The following project properties are used when publishing:
- group id:
project.group
- artifact id:
project.name
- version:
project.version
These default values can be changed by using further configuration in the build.gradle.kts
file of the project or the gradle.properties
file of the project as shown in the documentation.
The following additional properties can be added to the gradle.properties
file:
- kgp.repository.name: the name of the repository as it will appear in generated Gradle tasks. Default is
Artifactory
. - kgp.repository.url: the
URL
of the repository to publish to. Default is null.
plugins {
alias(libs.plugins.conventions.release)
}
This applies the dependency analysis android gradle plugin and the gradle versions plugin.
The plugin is applied by default to the root project when using the KGP Root Plugin.
Auto-applying the plugin can be disabled by setting the following property to false in the gradle.properties
file of the root project:
kgp.plugins.autoapply.dependencymanagement=false
To manually apply the plugin add the following to the root project build.gradle.kts
file:
plugins {
alias(libs.plugins.conventions.dependencyMaintenance)
}
- Reports on unused dependencies that should be removed
- Used transitive dependencies (which you may want to declare directly)
- Dependencies declared on the wrong configuration (api vs implementation vs compileOnly, etc.)
To run the dependency analysis plugin execute the following gradle task from the project root directory:
gradlew buildHealth
A report will be created in the {projectRoot}/build/reports/dependency-analysis
directory named build-health-report
in txt and json format by default.
- Reports on dependencies that have an update available
- Includes updates to Gradle
- Updates that are not considered stable (e.g., beta, snapshot) will not be included in the report by default
To run the gradle versions plugin and check for dependencies with an update execute the following gradle task from the project root directory:
gradlew dependencyUpdates
A report will be created in the {projectRoot}/build/dependencyUpdates
directory named report
in txt and json format by default. The files show what dependencies are up to date, which have newer versions available, and which dependency versions could not be checked.
The Kotlinter plugin is enabled by default for all projects that apply an Android plugin (application or library) or a kotlin plugin.
Auto-applying the plugin can be disabled by setting the following property to false in the gradle.properties
file of the project:
kgp.plugins.autoapply.kotlinter=false
A pre-commit hook to lint kotlin files can be created by running the createLintKotlinPreCommitHook
task from the root project. By default the task will create the hook in the .husky
directory if it exists, otherwise the hook will be created in the .git/hooks
directory. The hook executes the checkKotlinFiles
task which will run ktlint
against staged files for all configured projects. If a ktlint
violation exists the commit will be cancelled.
If you want ktlint
to try to auto-format staged files as a part of the commit then run the createFormatKotlinPreCommitHook
instead.
The checkKotlinFiles
task generates a report at build/lint-report.json
that shows any issues and the formatKotlinFiles
task generates a report at build/format-report.txt
that shows any formatting fixes made.
By default the Kotlinter
plugin version specifies what version of ktlint
is used. See the Kotlinter docs for details on how to override the ktlint
version if needed.
The following utility functions exist to help configure Dagger
:
dagger()
: adds thedagger
,javax:inject
, anddagger-compiler
dependencies. Optionally addsdagger-android-processor
,dagger-android
, anddagger-android-support
depending on the parameters used.
The following versions are expected in the Version Catalog when using the Dagger
utility function:
kgpDagger
: The version to use for dagger dependencies.
The following utility functions exist to help configure Deep Links
:
deepLink()
: adds thedeeplink
and KSPdeeplink-processor
dependencies. Defaults the deep link doc file to{buildDir}/doc/deeplinks.json
.
The following versions are expected in the Version Catalog when using the Deep Links
utility functions:
kgpDeepLink
: The version to use for deep link dependencies.
By default when the Android Application plugin is applied hilt will be auto-configured on the project.
Auto-configuration does the following:
- Applies the KAPT and Hilt Android plugins
KaptExtension.correctErrorTypes
: set to true- Dependencies
- Adds the Hilt Android Compiler dependency to the
kapt
,kaptTest
, andkaptAndroidTest
configurations. - Adds the Hilt Android Testing dependency to the
testImplementation
andAndroidTestImplementation
configurations.
Note: if using Hilt with androidx dependencies you must add the androidx hilt compiler and other needed dependencies.
- Adds the Hilt Android Compiler dependency to the
The following versions are expected in the Version Catalog when using Hilt auto-configuration:
kgpDagger
: The version to use for Hilt dependencies.kgpAndroidxHiltCompiler
: The version of the hilt compiler to use for compatible androidx library processing.
The following properties are used in the gradle.properties
file of projects to control how auto-configuration is applied:
kgp.android.autoconfigure.hilt.application
: if true then Hilt will be auto-configured when the Android Application plugin is applied. Default is true.kgp.android.autoconfigure.hilt.library
: if true then Hilt will be auto-configured when the Android Library plugin is applied. Default is false.
Enabling desugaring allows the use of newer Java APIs in older versions of Java. Desugaring can be auto-configured when the Android Application plugin or the Published Android Library plugin is applied.
Auto-configuration does the following:
android.compileOptions.isCoreLibraryDesugaringEnabled
: set to true- Dependencies:
- Adds the desugar jdk libs dependency to the
coreLibraryDesugaring
configuration.
- Adds the desugar jdk libs dependency to the
The following versions are expected in the Version Catalog when using desugaring auto-configuration:
kgpAndroidDesugarJdkLibs
: The version to use for thecom.android.tools:desugar_jdk_libs
dependency.
The following property is used in the gradle.properties
file of projects to control how auto-configuration is applied:
kgp.android.autoconfigure.corelibrarydesugaring
: if true then desugaring will be configured on supported projects. Default is false.
By default when an Android plugin is applied (Android Application or Published Android Library) then Jetpack Compose will be auto-configured.
Auto-configuration does the following:
android.buildFeatures.compose
: set to trueandroid.composeOptions.kotlinCompilerExtensionVersion
: set toandroidxComposeCompiler
version from Version Catalog.- Dependencies
- Adds the Jetpack Compose bill of materials and the default dependencies needed for Android Studio preview support and writing UI tests.
- Optionally adds further dependencies depending on the value of the
kgp.android.autoconfigure.compose.dependencies
property.
The following versions and bundle are expected in the Version Catalog when using Jetpack Compose auto-configuration:
kgpAndroidxComposeBom
: Jetpack Compose Bill of Materials version to use for Jetpack Compose dependencies.kgpAndroidxComposeCompiler
: Version of the Jetpack Compose Compiler to use. The version specified should be compatible with the version of the Kotlin Compiler Plugin used according to the Compatibility Map.kgpCompose
: This Bundle is only required in the Version Catalog if thekgp.android.autoconfigure.compose.dependencies
property is set tobundle
. If it is then thecompose
bundle is added to the dependencies of the project.
The following properties are used in the gradle.properties
file of projects to further control how auto-configuration is applied:
kgp.android.autoconfigure.compose
: if true then Jetpack Compose will be auto-configured on supported projects. Default is true.kgp.android.autoconfigure.compose.dependencies
: controls what additional compose dependencies are added by default to projects based on the values below.bundle
: adds dependencies from thecompose
bundle in the Version Catalog.material
: adds dependencies needed to use Material UI.material3
: adds dependencies needed to use Material3 UI. Also adds the core Material Icons.none
: does not add any additional dependencies. This is the default value.
A couple utility functions exist to help configure JUnit
dependencies:
junit5()
: adds thejunit-bom
BOM and thejunit-jupiter
dependencies to thetestImplementation
configuration.junitVintage()
: in addition to callingjunit5()
this will also addjunit4
to thetestImplementation
configuration and thejunit-vintage-engine
to thetestRuntimeOnly
configuration.
The following versions are expected in the Version Catalog when using the junit
utility functions:
kgpJunit4
: The version ofjunit4
. This is only required ifjunitVintage()
is used.kgpJunit5
: The version ofjunit5
.
The following utility function exists to help configure Kotlinx Serialization
:
kotlinxSerialization()
: adds theorg.jetbrains.kotlin.plugin.serialization
plugin. Ifjson
is true adds thekotlinx-serialization-json
dependency.
The following versions are expected in the Version Catalog when using the kotlinxSerialization()
utility functions:
kotlinxSerialization
: The version to use for Kotlinx Serialization dependencies.
The following utility function exists to help configure Moshi
:
moshi()
: adds themoshi
dependency. Ifcodegen
is truemoshi-kotlin-codegen
is added to theksp
configuration. IfmoshiAdapters
is truemoshi-adapters
is included. IfmoshiKoltlinReflect
is true thenmoshi-kotlin
is included.
The following versions are expected in the Version Catalog when using the moshi
utility functions:
kgpMoshi
: The version to use for Moshi dependencies.
Setting the default group and version for all subprojects can be disabled.
The following property is used in the root gradle.properties
file to control how auto-configuration is applied:
kgp.autoconfigure.publishingproperties
: if true then group and version will be set for all subprojects by the KGP Root Plugin. Default is true.
The following utility functions exist to help configure Room
:
room()
: adds theroom-runtime
,room-ktx
,room-compiler
dependencies.room-testing
and the room plugin are also added/applied if aschemaDirectory
is specified.
The following versions are expected in the Version Catalog when using the room
utility functions:
kgpAndroidxRoom
: The version to use for Room dependencies.