Build.gradle.kt does not find plugin


(Martin Domnick) #1

Hi,

I’ve got trouble setting up a new project with kotlin and gradle.

Here is my build.gradle.kt file

buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.11)
}
}

plugins {
id(“kotlin2js”) version Versions.kotlin
id(“kotlin-dce-js”) version Versions.kotlin
}

group = “com.foo”
version = “1.0-SNAPSHOT”

repositories {
mavenCentral()
}

dependencies {
compile(kotlin(“stdlib-js”))
}

After that I get the following error:

Plugin [id: ‘kotlin-dce-js’, version: ‘1.3.11’] was not found in any of the following sources:

  • Gradle Core Plugins (not a core plugin, please see https://docs.gradle.org/4.10/userguide/standard_plugins.html for available core plugins)
  • Plugin Repositories (could not resolve plugin artifact ‘kotlin-dce-js:kotlin-dce-js.gradle.plugin:1.3.11’)
    Searched in the following repositories:
    Gradle Central Plugin Repository

On the kotlin page is a documentation how to set up the plugin for a project, but it does not tell how it is done with gradle.kt
https://kotlinlang.org/docs/reference/javascript-dce.html

Can someone please help me, with that problem?


(Martin Domnick) #2

Ok I was now browsing through the other files and found a file called settings.gradle

with the following content

pluginManagement {
resolutionStrategy {
    eachPlugin {
        if (requested.id.id == "kotlin2js") {
            useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:${requested.version}")
        }
    }
}

}

So I added the following lines

        if (requested.id.id == "kotlin-dce-js") {
            useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:${requested.version}")
        }

And now it compiles. Can anyone please explain me why this is required?


(Martin Domnick) #3

Ok no after reading that article:


I get it. So “apply” is legacy, allthough in this case in my humble opinion much simpler

Do I need to use the new “plugin” block for kotlin?

When I write it like that:

apply {
plugin(“kotlin-dce-js”)
}

plugins {
id(“kotlin2js”) version Versions.kotlin
}

The build actually runs through.

But I can not replace the plugins line completly and put kotlin2js into the old apply block because then it says

Line 24: compile(kotlin(“stdlib-js”))
^ Unresolved reference: compile