Home > database >  gradle with wsdl2java plugin
gradle with wsdl2java plugin

Time:12-31

I'm using no.nils.wsdl2java plugin, full gradle.build file looks like:

plugins {
    id 'org.springframework.boot' version '2.3.4.RELEASE'
    id 'io.spring.dependency-management' version '1.0.12.RELEASE'
    id 'java'
    id "no.nils.wsdl2java" version "0.10"
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

configurations {
    jaxb
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenCentral()
}
dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    compileOnly 'org.projectlombok:lombok'
    runtimeOnly 'com.oracle.database.jdbc:ojdbc8'
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    implementation group: 'com.oracle.ojdbc', name: 'orai18n', version: '19.3.0.0'
    implementation 'org.springframework.boot:spring-boot-starter-security'
    implementation 'com.google.code.gson:gson:2.8.5'
}

tasks.named('test') {
    useJUnitPlatform()
}
wsdl2java {
    generatedWsdlDir = file("build/generated/wsdl/Service")
    wsdlsToGenerate = [
            ['-p', 'Service', '-wsdlLocation', 'classpath:wsdl/Service.wsdl',
             '-autoNameResolution', "src/main/resources/wsdl/Service.wsdl"]
    ]
}

When i'm building project with gradle jvm version 11, getting exception:

Unable to load class 'jakarta.xml.bind.JAXBException'.

** But on version 8 getting error :

org/apache/cxf/tools/wsdlto/WSDLToJava has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0.

I know about javax -> jakarta namespace migration but how to fix my problem?

CodePudding user response:

In your build.gradle add this:

wsdl2javaExt {
    cxfVersion = "3.5.5"
}

to specify Apache CXF version explictly. It should compile with Java 8 correctly.


Well, the error says that org/apache/cxf/tools/wsdlto/WSDLToJava is compiled with Java 11, but your project use Java 8. This class is loaded by wsdl2java plugin:

 def wsdlToJava = classLoader.loadClass("org.apache.cxf.tools.wsdlto.WSDLToJava").newInstance()

and it's part of Apache CXF project. To see where it comes from you can print dependency tree:

./gradlew app:dependencies --configuration wsdl2java

in result you can find:

 --- org.apache.cxf:cxf-tools-wsdlto-databinding-jaxb:  -> 4.0.0
...
|     --- org.apache.cxf:cxf-tools-wsdlto-core:4.0.0

the version of org.apache.cxf:cxf-tools-wsdlto-databinding-jaxb is set to , so the gradle uses the newest version and at now it's 4.0.0. The plugin adds this dependencies in those lines:

            // add cxf as dependency
            project.dependencies {
                wsdl2java "org.apache.cxf:cxf-tools-wsdlto-databinding-jaxb:$cxfVersion"

$cxfVersion is set by default to , but you can override it in build.gradle with the following code:

wsdl2javaExt {
    cxfVersion = "3.5.5"
}

to use the previous Apache CXF version (which is compatible with Java 8)

  • Related