1

From https://kotlinlang.org/docs/tutorials/javascript/getting-started-gradle/getting-started-with-gradle.html I got the following build.gradle (groovy) script :

group 'org.example'
version '1.0-SNAPSHOT'

buildscript {
    ext.kotlin_version = '1.3.61'
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

apply plugin: 'kotlin2js'

repositories {
    mavenCentral()
}

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
}

I tried this translation :

group 'org.example'
version '1.0-SNAPSHOT'

buildscript {
    extra["kotlinVersion"]  = "1.3.61"
    repositories {
        jcenter()
    }
    dependencies {
    classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${extra["kotlinVersion"]}")
    }
}

plugins {
    kotlin2js  // <= this is incorrect
    application
}

repositories {
    mavenCentral()
}

dependencies {
    implementation("org.jetbrains.kotlin:kotlin-stdlib-js:${extra["kotlinVersion"]}")
}

application {
    mainClassName = "io.ipfs.kotlin.MainIpfsKt"
}

gradle emits the following error message

kotlin2js
^ Unresolved reference: kotlin2js

What is the correct translation for apply plugin: 'kotlin2js' ?

Emile Achadde
  • 1,715
  • 3
  • 10
  • 22
  • Have you tried `id 'kotlin2js` ...` (prefix with `id`, put plugin name in quotes – cfrick Mar 03 '20 at 15:43
  • I tried * id("kotlin2js") version "1.3.21"* it is better but now the version is incorrect : ```Plugin [id: 'kotlin2js', version: '1.3.21'] was not found in any of the following sources* - Gradle Core Plugins (not a core plugin, please see https://docs.gradle.org/4.10.2/userguide/standard_plugins.html for available core plugins) - Plugin Repositories (could not resolve plugin artifact 'kotlin2js:kotlin2js.gradle.plugin:1.3.21') Searched in the following repositories: Gradle Central Plugin Repository ``` – Emile Achadde Mar 03 '20 at 16:08
  • 1
    Where did you get that build file that uses the Groovy DSL? The link you provided gives working examples using the Kotlin DSL (where you can also see that the correct way of declaring the plugin is with `id("org.jetbrains.kotlin.js") version "1.3.61"`) – Bjørn Vester Mar 04 '20 at 13:42
  • @ Bjørn Vester my example is a mixture of https://kotlinlang.org/docs/tutorials/javascript/setting-up.html and https://github.com/gradle/kotlin-dsl-samples/blob/master/samples/hello-js/build.gradle.kts. I only wanted to write the simplest build to produce js code from kotlin with gradle. – Emile Achadde Mar 04 '20 at 14:07

0 Answers0