What is the difference between org.jetbrains.kotlin.android
and org.jetbrains.kotlin:kotlin-gradle-plugin
in android? What is the relationship between them and kotlin-android
?
org.jetbrains.kotlin.android
is the public plugin id of the Kotlin Android Gradle plugin, with which you can directly apply that plugin from a public repository, ie you can simply write:
plugins {
id("org.jetbrains.kotlin.android") version "2.0.0"
}
with no other configuration. See its page at the Gradle Plugin Portal. Kotlin DSL also offers the shorthand notation
plugins {
kotlin("android") version "2.0.0"
}
which is equivalent.
org.jetbrains.kotlin:kotlin-gradle-plugin
is the group and artifact name in Maven coordinates of the JAR containing the Kotlin Gradle plugins (which includes all the plugins for Kotlin compilation to Android, JVM and multiplatform targets, plus Kapt). You can use this to add the JAR to a program classpath like any other dependency. For example I can write:
plugins {
java
}
dependencies {
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.0")
}
This will allow me to compile a Java program which has access to all the classes of the Kotlin Gradle plugins.
You also see these coordinates referred to on the Kotlin Android plugin's page at the Gradle Portal linked above, where it shows you how to add the JAR to the buildscript classpath and apply the Kotlin Android plugin from it using the Gradle's legacy apply method.
kotlin-android
is also a plugin id of the Kotlin Android Gradle plugin, but it is not registered under that id on the Gradle Plugin Portal. It can be used when the Kotlin Gradle plugins JAR is already on the build classpath.
For example, in the root build.gradle.kts
file I can firstly do:
buildscript {
repositories {
gradlePluginPortal()
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.0")
}
}
which puts the Kotlin Gradle plugins code on the build classpath. Then, in any subproject I can do:
plugins {
id("kotlin-android")
}
to apply the Kotlin Android Gradle plugin, which can be found as the code for the plugins is on the build classpath. Note you must not include a version if you are applying a plugin like this from code already on the classpath.
I could also have replaced this snippet in the subproject with either of the code samples from part 1. as they are entirely equivalent, though without the version specified.