Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define the Kotlin version for both buildSrc and an application module?

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?

Related

  • Gradle Kotlin DSL: Define Kotlin version in unique place
  • Kotlin versions and the Gradle Kotlin DSL
  • Sample project: Multi-kotlin-project-with-buildSrc
like image 421
JJD Avatar asked Mar 27 '18 20:03

JJD


People also ask

How do I change my kotlin Android version?

In your Android studio, Go to Tools -> Kotlin -> Configure Kotlin Updates.

What is buildSrc in gradle?

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.

How do I update kotlin in flutter?

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.

What is kotlin plugin used for?

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.


2 Answers

Each Gradle release is meant to be used with a specific version of the kotlin-dsl plugin and compatibility between arbitrary Gradle releases and kotlin-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()
}
like image 164
JJD Avatar answered Oct 11 '22 17:10

JJD


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)
            }
        }
    }
}
like image 33
Czar Avatar answered Oct 11 '22 18:10

Czar