Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugin does not work for kotlin dsl #7

Open
groupcard-ruben-timmermans opened this issue Jun 24, 2024 · 5 comments
Open

plugin does not work for kotlin dsl #7

groupcard-ruben-timmermans opened this issue Jun 24, 2024 · 5 comments

Comments

@groupcard-ruben-timmermans
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.

@deepy
Copy link
Member

deepy commented Jun 25, 2024

From memory I think the kotlin equivalent is ` instead of ', but I'll add a kotlin example tomorrow

@groupcard-ruben-timmermans
Copy link
Author

also tried with the backticks but they don't work either, thanks for adding an example.

@groupcard-ruben-timmermans
Copy link
Author

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

@deepy
Copy link
Member

deepy commented Jun 26, 2024

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

@deepy
Copy link
Member

deepy commented Jul 6, 2024

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"))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants