How to build test jar with new kotlin/js plugin an...
# javascript
r
How to build test jar with new kotlin/js plugin and kotlin dsl? Currently with old plugin and groovy dsl I use this:
Copy code
task testJar(type: Jar, dependsOn: testClasses) {
    baseName = "${project.archivesBaseName}"
    classifier = "tests"
    from sourceSets.test.output
}
When I try to just do the same thing I've got an error
> SourceSet with name 'test' not found.
.
i
If you use
multiplatform
plugin, source set’s name is
jsTest
r
No, I'm using
js
plugin
I've checked - sourceSets collection is empty
I can use kotlin.sourceSets but I don't know how to get
output
i
I need to check it, but anyway it is gradle live collection, so you can subscribe on its changing with
sourceSets.all { }
and if it will be fulfilled, closure should be executed
r
It's not executed
i
Ok, I see your problem. Firstly, new js plugin and multiplatform now works in the similar mechanism. It is right, that you need to use our own
kotlin.sourceSets
because we don’t register in common case it in default gradle source sets (because we need complex case with mutiplatform)
KotlinSourceSet
doesn’t contain output, because it is only source set (for example in MPP you can have
common
and
js
source sets, and definition of output of source set is undefined). We have another abstraction, that contain output, it is
compilation
, so you can use this
Copy code
from(kotlin.target.compilations["test"].output.allOutputs)
r
I've managed to also get it work with
from(tasks["compileTestKotlinJs"].outputs)
which would be better?
i
I think, that with compilation is more flexible, because in theory compilation output may be wider than only compile task output
🙏 1