2

I have kotlin2js plugin with task compileKotlin2Js. I configure it like this:

val compileKotlin2Js: Kotlin2JsCompile by tasks
compileKotlin2Js.kotlinOptions {
    main = "call"
    outputFile = "${projectDir}/build/app.js"
}

Now I want to create similar task, but with other kotlinOptions. For example:

.kotlinOptions {
    main = "noCall"
    outputFile = "${projectDir}/build/lib.js"
}

How to do it?

UPDATE: I also tried to do some thing like this:

tasks.register<Kotlin2JsCompile>("myCompile2Js") {
    kotlinOptions {
        main = "noCall"
        outputFile = "${projectDir}/build/lib.js"
    }
}

But it produce error:

Execution failed for task ':myCompile2Js'.
> lateinit property destinationDirProvider has not been initialized

I also tried to specify destinationDir. Error disappear, but such task does not produce any build.

leaf
  • 87
  • 11

1 Answers1

0

I haven't tested it, but I believe something like the following should do the trick:

tasks.register<Kotlin2JsCompile>("myCompile2Js") {
    kotlinOptions {
        main = "noCall"
        outputFile = "${projectDir}/build/lib.js"
    }
}

Or if you need a reference to the task later on:

val myCompile2Js by tasks.creating(Kotlin2JsCompile::class)
myCompile2Js.kotlinOptions {
    main = "noCall"
    outputFile = "${projectDir}/build/lib.js"
}
Joffrey
  • 32,348
  • 6
  • 68
  • 100
  • I tried it too. But it don' work. Produce error `Execution failed for task ':myCompile2Js'. > lateinit property destinationDirProvider has not been initialized`. And I also tried to specify `destinationDir`. It avoid error, but task do nothing. – leaf May 31 '19 at 09:06
  • @leaf I see then. Maybe you can take a look at how they create the task in the plugin, maybe there is more initialization required when creating a custom one. I don't the details of the kotlin JS plugin myself unfortunately. – Joffrey May 31 '19 at 09:20