Use with Kotlin
nieldw opened this issue · 3 comments
nieldw commented
This plugin doesn't work out of the box with Kotlin.
To make your build pass, add the following to your (groovy) build.gradle
file:
xjc {
includeInMainCompilation = false
}
sourceSets {
main { java { srcDir xjcGenerate.outputDirectory } }
}
compileKotlin {
dependsOn xjcGenerate
}
Here's a working, complete build.gradle
file assuming an XSD file in the default src/main/schema
location: https://gist.github.com/nieldw/db9b46bebbfcf8c704a3b21d7e92fa01
frost13it commented
There is a simpler workaround:
sourceSets.main.java.srcDir(xjcGenerate)
It seems that generated sources are not visible from Kotlin side because of two issues:
- The
xjcGenerate
task (instead of it's output directory) should be added to Java sources dirs. In this case it will be considered a dependency ofcompileJava
andcompileKotlin
automatically.
It could be fixed here easily. - Kotlin plugin does not pick up Java source directories which added in
afterEvaluate { }
after it was applied.
I think it should be fixed in Kotlin plugin. As a workaround you can apply XJC plugin before Kotlin plugin.
mdiskin commented
I'm struggling to get this and the duplicate task in kotlin to work and keep getting NPE.
tkrullmann commented
Version 2.0 is a complete rewrite in Kotlin, so Kotlin DSL support is now first class :-)
The plugin will also work on each source set by default, so this should no longer be an issue