plugin does not work for kotlin dsl
groupcard-ruben-timmermans opened this issue · 5 comments
jaxb2 {
xjc {
'request-classes' {
basePackage = 'com.any.app.model.request'
schema = 'src/main/xsd/request.xsd'
}
}
}
I tried to make this work using kotlin dsl for gradle but ufortunately 'request-classes' can't be invoked as a function.
Trying other things like create("request-classes") {....} or register("request-classes") {....} doesn't work either. Can you provide a working example for kotlin dsl (build.gradle.kts)? Thanks in advance.
From memory I think the kotlin equivalent is ` instead of ', but I'll add a kotlin example tomorrow
also tried with the backticks but they don't work either, thanks for adding an example.
interestingly when i use the above script in groovy dsl i get a smilar error. Here is the snippet of my build.gradle:
jaxb2 {
xjc {
'request-classes' {
basePackage = 'nl.groupcard'
schema = 'src/main/resources/stuf/somefile.xsd'
encoding = 'UTF-8'
extension = true
}
'generation-step-name' {
generatedSourcesDir = 'build/generated'
}
}
}
and part of the stacktrace:
Caused by: java.lang.NullPointerException: Cannot invoke method replace() on null object
at com.gradleup.jaxb.tasks.GenerateJaxb2Classes.antXjc(GenerateJaxb2Classes.groovy:46)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:125)
This and the fact that the generatedSourcesDir IS created but with the default value seems to hint that no fields such as basePackage or generatedSourcesDir are actually set.
I forgot to mention, i use gradle 8.8 along with jdk21
A quick test shows that this works on 8.8 java 8
jaxb2.xjc.register("request-classes") {
schema = "src/main/xsd/request.xsd"
basePackage = "com.gradleup.generated.model"
generatedSourcesDir = "src/generated/java"
}
But throws an error on java 11 so presumably also on JDK 21, I should be able to get to that this weekend though
I can't get the error to reproduce, so can confirm this works fine on JDK 21+
You just need the jaxb-api dependency (like: jaxb2("javax.xml.bind:jaxb-api:2.3.1")
)