3

Migrating from Groovy to Kotlin and stumbled on a simple problem on wsdl2java generation.

Question is simple, does anyone have good example with it. Google wasn't very helpful and not good in Kotlin DSL yet also syntax wise.

Also using OpenJDK11.


plugins {
  id("no.nils.wsdl2java") version "0.10"
}


wsdl2java {
  enabled = true
  wsdlsToGenerate = [
    [
      "-xjc",
      "-p", "bla.bla.generated",
      "-wsdlLocation", "classpath:wsdl/v1.wsdl",
      "-autoNameResolution", "$projectDir/src/main/resources/wsdl/v1.wsdl"
    ],
    [
      "-xjc",
      "-p", "bla.bla.generated",
      "-wsdlLocation", "classpath:wsdl/v2.wsdl",
      "-autoNameResolution", "$projectDir/src/main/resources/wsdl/v2.wsdl"
    ]]
  generatedWsdlDir = file("$projectDir/src/main/java")
  wsdlDir = file("$projectDir/src/main/resources/wsdl")
}

dependencies {

  implementation(project(":common"))
  implementation(project(":etcd"))

  implementation("org.springframework.boot:spring-boot-starter-actuator")
  implementation("org.springframework.boot:spring-boot-starter-data-jpa")
  implementation("org.springframework.boot:spring-boot-starter-hateoas")
  implementation("org.springframework.boot:spring-boot-starter-quartz")
  implementation("org.springframework.boot:spring-boot-starter-security")
  implementation("org.springframework.boot:spring-boot-starter-validation")
  implementation("org.springframework.boot:spring-boot-starter-web")
  implementation("org.springframework.boot:spring-boot-starter-web-services")

  api("no.nils:wsdl2java")

  compileOnly("org.projectlombok:lombok")
  testImplementation("org.springframework.boot:spring-boot-starter-test")
  testImplementation("org.springframework.security:spring-security-test")
}

tasks.jar {
  archiveFileName.set("ext.jar")
}



mkasepuu
  • 243
  • 5
  • 13

2 Answers2

4

I got wsdl2java working through trial and error with the following:

plugins {
    id("no.nils.wsdl2java") version "0.10"
}

wsdl2javaExt {
    cxfVersion = "3.3.0"
    deleteGeneratedSourcesOnClean = true
}

tasks.withType<no.nils.wsdl2java.Wsdl2JavaTask> {
    // The use of ArrayList(listOf) is necessary as the Wsdl2JavaTask seems to make inline changes to its arguments
    wsdlsToGenerate = listOf(
            ArrayList(listOf("-p", "dk.grydholt.integration.sacho",
                    "-autoNameResolution", "-xjc-npa",
                    "-wsdlLocation", "classpath:wsdl/sacho/EduModelService.wsdl",
                    "$projectDir/src/main/resources/wsdl/sacho/EduModelService.wsdl")))

    generatedWsdlDir = file("$projectDir/src/generated/java")
    wsdlDir = file("$projectDir/src/main/resources/wsdl/sacho")
}

sourceSets {
    create("generated") {
        java.srcDirs(listOf("src/generated/java"))
    }
}

Notice the use of ArrayList. It took me some time to debug as you'll get strange type errors if you do listOf(listOf("...")).

0

you could do it like:

plugins {
    id("no.nils.wsdl2java") version "0.12"
}

dependencies {
    // SOAP dependencies
    implementation("org.springframework.boot:spring-boot-starter-web-services") {
        exclude(module = "spring-boot-starter-tomcat")
    }
    implementation("org.glassfish.jaxb:jaxb-runtime")
    implementation("org.apache.cxf.xjc-utils:cxf-xjc-runtime:3.3.1")
}

wsdl2java {
    wsdlDir = file("$projectDir/src/main/wsdl")
    wsdlsToGenerate = listOf(
        // look here for other parameters: https://cxf.apache.org/docs/wsdl-to-java.html
        listOf(
            // activate plugin to add a toString() method to generated classes
            // equivalent to: -Xts:style:org.apache.cxf.xjc.runtime.JAXBToStringStyle.DEFAULT_STYLE
            "-xjc-Xts",
            // generate getters methods for Booleans
            "-xjc-Xbg",
            // adds the @Generated annotation to classes generated.
            "-mark-generated",
            // automatically resolve naming conflicts without requiring the use of binding customizations.
            "-autoNameResolution",
            // map each of the namespaces to its own java package
            // this is done 'cause the namespaces are conflicting between the different WSDLs files
            // we have, which is leading to class overwriting during code generation
            // you should look up these URLs in the WSDLs and come with package names in case
            // you find out about conflicts
            "-p", "http://xxx/xi/A1S/Global=e.r.t.y",
            "-p", "http://xxx/xi/A1S/Global=e.r.t.ye",
            "-p", "http://xxx/xi/A1S/Global=e.r.t.xer",
            "$wsdlDir/mywsdl.wsdl"
        )
    )
}

however, `no.nils.wsdl2java` plugin does not work for gradle 7.*
hitesh
  • 176
  • 1
  • 3