Can anyone help convert the following gradle task ...
# gradle
a
Can anyone help convert the following gradle task from
JavaCompile
to
KotlinCompile
or equivalent?
Copy code
task compileStubs(type: JavaCompile) {
    JavaCompile compileJava = project.getTasksByName("compileJava", true).toArray()[0]
    classpath = compileJava.classpath
    source = project.getLayout().getBuildDirectory().dir("generated-stub-sources")
    def stubsClassesDir = file("${project.getBuildDir()}/generated-stub-classes")
    destinationDir(stubsClassesDir)
    compileJava.finalizedBy(compileStubs)
}
This is the Groovy DSL in case that wasn't obvious
e
why do it that way? if you add your generated sources to the main sourceset, everything will work whether it's java or kotlin or multiplatform
a
Sorry, I don't understand your question. I want a separate jar file for the generated code
e
it would be easiest to use a separate module for that, but you could create a sourceset. how do you expect your consumers to use it if it's a separate jar file though…
a
It gets published as a separate maven dependency
e
then a separate module would be best
a
This is the library that I am referencing: https://github.com/lsd-consulting/spring-wiremock-stub-generator
It generates wiremock stubs of a spring controller. The stubs are currently in Java, partly due to this issue I posted above. If we could come up with a Kotlin equivalent then the library could generate kotlin stubs instead of Java
e
just using Gradle's Java features,
Copy code
val wiremocksSourceSet = sourceSets.create("wiremocks") {
    java.srcDir(layout.buildDirectory.dir("generated-stub-sources"))
}
java.registerFeature("wiremocks") {
    usingSourceSet(wiremocksSourceSet)
}
will create a
${project.name}-wiremocks.jar
and add it to the publication, and since it goes through the usual sourceset registration, Kotlin works
a
I'll give it a shot