使用Gradle Kotlin DSL和wsdl2java

3

从Groovy迁移到Kotlin,在wsdl2java生成过程中遇到了一个简单的问题。

问题很简单,有人有相关的好例子吗?谷歌并没有提供很好的帮助,Kotlin DSL在语法方面也不是很好。

同时使用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")
}



2个回答

4

我通过反复尝试使wsdl2java工作,并使用以下方法:

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

注意ArrayList的使用。如果你使用listOf(listOf("..."))会导致奇怪的类型错误,因此我花了一些时间进行调试。


0

你可以这样做:

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.*

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接