I am using a buildSrc
module in a multi-module Kotlin project to manage dependency definitions and versions. The module makes use of kotlin-dsl as shown in the build.gradle.kts:
plugins {
`kotlin-dsl`
}
Alternative declaration:
plugins {
id("org.gradle.kotlin.kotlin-dsl") version "0.16.2"
}
I would like to use the same Kotlin version for compiling the buildSrc
module as well as within the application module/s. My first attempt was to simply add the JVM artifact:
plugins {
`kotlin-dsl`
kotlin("jvm") version "1.2.31"
}
This however leads to a build error which is discussed here:
Error resolving plugin [id: 'org.jetbrains.kotlin.jvm', version: '1.2.31']
Plugin request for plugin already on the classpath must not include a version
What is a convenient way to only define once the Kotlin version used throughout the project?
In your Android studio, Go to Tools -> Kotlin -> Configure Kotlin Updates.
buildSrc is a separate build whose purpose is to build any tasks, plugins, or other classes which are intended to be used in build scripts of the main build, but don't have to be shared across builds.
All you need to do is to open the <your project>/android/build. gradle file then update ext. kotlin_version to a newer version: At the time of writing, the latest version is 1.6.
The Kotlin Multiplatform Gradle plugin is a tool for creating Kotlin Multiplatform projects. Here we provide a reference of its contents; use it as a reminder when writing Gradle build scripts for Kotlin Multiplatform projects. Learn the concepts of Kotlin Multiplatform projects, how to create and configure them.
Each Gradle release is meant to be used with a specific version of the
kotlin-dsl
plugin and compatibility between arbitrary Gradle releases andkotlin-dsl
plugin versions is not guaranteed.Using an unexpected version of the
kotlin-dsl
plugin in a build can cause hard to diagnose problems.Starting with Gradle 5.4, a warning is emitted whenever an unexpected version of the
kotlin-dsl
plugin is detected.
Paul Merlin @eskatos, 25.04.2019
Therefore, I removed the version
:
plugins {
`kotlin-dsl`
}
repositories {
mavenCentral()
}
The only way I'm aware of is putting it into gradle.properties (or any other config) and reading it in settings.gradle.kts pluginManagement
. Like this:
pluginManagement {
repositories {
gradlePluginPortal()
}
resolutionStrategy {
eachPlugin {
if (requested.id.id.startsWith("org.jetbrains.kotlin")) {
useVersion(gradle.rootProject.extra["kotlin.version"] as String)
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With