What are the difference between this three Kotlin plugin and what they actually do?
plugins {
id 'kotlin-android'
id 'org.jetbrains.kotlin.android'
id "org.jetbrains.kotlin.jvm" version "1.6.20"
}
The third one seems to be the recommended way specially when using Kotlin Coroutines
>Solution :
These plugins provide integration with different other Gradle plugins. They both setup compiling Kotlin for the JVM, but aim to interoperate with different other tools.
-
org.jetbrains.kotlin.android
orkotlin-android
This plugin offers integration of Kotlin with the Android Gradle plugin, which should also be applied to the project. The Kotlin compilations are set up to be included in the builds of Android variants (e.g.
debug
,release
,testDebug
etc.)The IDs
kotlin-android
andorg.jetbrains.kotlin.android
designate the same Gradle plugin. The only difference is that the "full" IDorg.jetbrains.kotlin.android
can be used for resolving the plugin from the Gradle Plugin Portal, while the shorter IDkotlin-android
can only be used for applying the plugin that you already have on the classpath. -
org.jetbrains.kotlin.jvm
This is the plugin for building Kotlin projects that target JVM without Android support.
The plugin offers integration with the Gradle
java
plugin (as well asjava-library
orapplication
). The project that applies this plugin can also use Java sources. The Kotlin compilations are wired with thejava
plugin’s source sets (main
andtest
by default)
Normally you should only apply one of these plugins, depending on whether you target Android or "standard" JVM. If you need to target both platforms, you should use the Kotlin Multiplatform by ID org.jetbrains.kotlin.multiplatform
, which adds the DSL to setup the targets in the project. Those might include jvm()
, android()
as well as other targets: JS, Kotlin/Native.