ciscoo / cxf-codegen-gradle

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

Enabling CXF xjc extentions #42

Closed mdiskin closed 2 years ago

mdiskin commented 2 years ago

see xjc extentions

It would be great if support of org.jvnet.jaxb2_commons:jaxb2-basics was there too but not sure if that needs to be logged in CXF issue side.

config: toolOptions { markGenerated.set(true) extraArgs.set([ "-xjc-Xts"]) }

output: `WSDLToJava Error: XJC reported 'BadCommandLineException' for -xjc argument:-extension -Xts Available plugin options: -Xinject-code : inject specified Java code fragments into the generated code -Xlocator : enable source location support for generated code -Xsync-methods : generate accessor methods with the 'synchronized' keyword -mark-generated : mark the generated code as @javax.annotation.Generated -noDate : do not add date -Xann : generate instead of @javax.annotation.Generated -episode : generate the episode file for separate compilation -Xpropertyaccessors : Use XmlAccessType PROPERTY instead of FIELD for generated classes -XBeanVal : convert xsd restrictions to javax.validation annotations. Usage with mods: -XBeanVal jsr303 simpleRegex

FAILURE: Build failed with an exception.`

ciscoo commented 2 years ago

You need to include the dependencies for the extension you want to use. That is shown in the Maven example near the bottom:

  <dependencies>
    <dependency>
      <groupId>org.apache.cxf.xjcplugins</groupId>
      <artifactId>cxf-xjc-ts</artifactId>
      <version>${cxf-xjc.version}</version>
    </dependency>
  </dependencies>
</plugin>

So full Gradle example:

import io.mateo.cxf.codegen.wsdl2java.Wsdl2Java

plugins {
    java
    id("io.mateo.cxf-codegen") version "1.0.1"
}

java {
    toolchain {
        languageVersion.set(JavaLanguageVersion.of(17))
    }
}

repositories {
    mavenCentral()
}

dependencies {
    cxfCodegen("jakarta.xml.ws:jakarta.xml.ws-api:2.3.3")
    cxfCodegen("jakarta.annotation:jakarta.annotation-api:1.3.5")
    cxfCodegen("org.apache.cxf.xjcplugins:cxf-xjc-ts:3.3.2")
}

tasks.register("calculator", Wsdl2Java::class) {
    toolOptions {
        wsdl.set(layout.projectDirectory.file("calculator.wsdl"))
        markGenerated.set(true)
        xjcArgs.add("-Xts")
    }
}

I've opened https://github.com/ciscoo/cxf-codegen-gradle/issues/43 to improve documentation.

mdiskin commented 2 years ago

Thank you that worked; I did leave a comment on #43 for an additional dependency that introduced.