ciscoo / cxf-codegen-gradle

Gradle plugin to generate Java artifacts from WSDL
Apache License 2.0
26 stars 6 forks source link

cxfVersion 4.0.0 missing runtime dependencies #77

Closed epozuelo closed 1 year ago

epozuelo commented 1 year ago

Hi,

I'm using plugin version 1.2.0 with gradle 7.6.1 and cxfVersion 4.0.0. My task looks like this:

import io.mateo.cxf.codegen.wsdl2java.Wsdl2Java
tasks.register("wsdl", Wsdl2Java) {
    toolOptions {
        wsdl.set(file("src/main/resources/service.wsdl"))
        // see https://github.com/ciscoo/cxf-codegen-gradle/issues/73
        wsdlLocation.set("classpath:src/main/resources/service.wsdl")
        outputDir.set(file("$buildDir/generated-java"))
    }
}

If I run gradle wsdl2java, I get:

Task :wsdl FAILED
Exception in thread "main" java.lang.NoClassDefFoundError: jakarta/xml/bind/JAXBException
        at org.apache.cxf.tools.wsdlto.WSDLToJava.<init>(WSDLToJava.java:48)
        at org.apache.cxf.tools.wsdlto.WSDLToJava.main(WSDLToJava.java:181)
Caused by: java.lang.ClassNotFoundException: jakarta.xml.bind.JAXBException
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
        ... 2 more

FAILURE: Build failed with an exception.

If I add this dependency it doesn't fail that way anymore (it fails initializing the jaxb plugin though, but I'll open a separate issue for that):

dependencies {
    cxfCodegen "jakarta.xml.bind:jakarta.xml.bind-api:4.0.0"
}

Given this is a codegen dependency, maybe it should be handled automatically by the codegen plugin?

ciscoo commented 1 year ago

This is expected behavior.

This plugin (io.mateo.cxf-codegen) only provides dependencies for Apache CXF, not Jakarta specific dependencies. Jakarta specific dependencies, such as Jakarta XML Binding, are to be provided by the projects themselves.

The reason for this is because I do not think it is appropriate for this plugin to provide such dependencies. The plugin is only responsible for providing an API for Gradle over the underlying code generation tool (wsdl2java). The plugin is not going to decide whether a project is to be Jakarta EE 9, 9.1, 10, etc. That is left to the projects to decide which version of the specification their project requires.