https://kotlinlang.org logo
#dsl
Title
# dsl
g

GarouDan

02/25/2019, 6:29 PM
Hi, does someone know how can I translate this task to
build.gradle.kts
?
Copy code
compileTestKotlin2Js {
    kotlinOptions.metaInfo = true
    kotlinOptions.outputFile = "$project.buildDir.path/js-tests/${project.name}-tests.js"
    kotlinOptions.sourceMap = true
    kotlinOptions.moduleKind = 'commonjs'
//    kotlinOptions.moduleName = project.name + "-test"
    kotlinOptions.main = "call"
}
This one here I could do something like:
Copy code
compileKotlin2Js {
    kotlinOptions.metaInfo = true
    kotlinOptions.outputFile = "$project.buildDir.path/js/${project.name}.js"
    kotlinOptions.sourceMap = true
    kotlinOptions.moduleKind = 'commonjs'
    kotlinOptions.main = "call"
}
Copy code
tasks.withType<Kotlin2JsCompile> {
	kotlinOptions {
		//		languageVersion = "1.3"
		metaInfo = true
		outputFile = "${project.buildDir.path}/js/${project.name}.js"
		sourceMap = true
		sourceMapEmbedSources = "always"
		moduleKind = "commonjs" // umd
		main = "call"
	}
}
I tried something like:
Copy code
tasks {
  "compileKotlin2Js"(Kotlin2JsCompile::class) {
    kotlinOptions {
      metaInfo = true
      outputFile = "${project.buildDir.path}/js/${project.name}.js"
      sourceMap = true
      sourceMapEmbedSources = "always"
      moduleKind = "commonjs"
      main = "call"
    }
  }

  "compileTestKotlin2Js"(Kotlin2JsCompile::class) {
    kotlinOptions {
      metaInfo = true
      outputFile = "${project.buildDir.path}/js-tests/${project.name}-tests.js"
      sourceMap = true
      moduleKind = "commonjs"
      main = "call"
    }
  }
}
but it didn’t work
c

Czar

02/25/2019, 7:18 PM
This channel is for DSL design, for gradle kotlin-dsl the proper channel is #gradle
That said, proper way to do what you're trying to do is:
Copy code
tasks {
    named<Kotlin2JsCompile>("compileKotlin2Js") {
        //...
    }
}
or if the task doesn't exist and you're creating it:
Copy code
tasks {
   register<Kotlin2JsCompile>("compileKotlin2Js") {
       //...
   }
}
g

GarouDan

02/26/2019, 1:20 AM
Ok, I’ll use the #gradle next time. Thanks for the explanation. Unfortunately it didn’t worked, since the tasks should exist. It looks like because I’m using
kotlin("multiplatform")
instead of
id("kotlin2js")
plugin it didn’t work. I’ll be asking in the #javascript channel, but if you know how can I solve this problem I’ll appreciate.
c

Czar

02/26/2019, 7:19 AM
I haven't worked with either, sorry and good luck 🙂
2 Views