Balaji211
Balaji211

Reputation: 307

cxf-codegen-plugin in Gradle

I have below plugin in maven which is working fine. Now, I need to use the gradle version of project, so need to use the plugin in gradle. I tried below, but I am getting mentioned error. I am using Java 11. Any help/Suggestion is appreciable.

<plugin>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-codegen-plugin</artifactId>
            <version>3.4.5</version>
            <executions>
                <execution>
                    <id>generate-sources</id>
                    <phase>generate-sources</phase>
                    <configuration>
                        <sourceRoot>${basedir}/src/main/java</sourceRoot>
                        <wsdlOptions>
                            <wsdlOption>
                                <wsdl>${basedir}/src/main/resources/wsdl/CarServices.wsdl
                                </wsdl>
                                <wsdlLocation>classpath:wsdl/CarServices.wsdl
                                </wsdlLocation>
                            </wsdlOption>
                        </wsdlOptions>
                    </configuration>
                    <goals>
                        <goal>wsdl2java</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

Below is the build.gradle file content

    configurations {
        wsdl2java
    }

    dependencies {
        compile "org.apache.cxf:cxf-spring-boot-starter-jaxws:3.4.5"
    compile 'org.apache.cxf:cxf-rt-frontend-jaxws:3.4.5'
    compile 'org.apache.cxf:cxf-rt-transports-http:3.4.5'

    compile 'javax.xml.ws:jaxws-api:2.3.0'
    compile 'javax.jws:jsr181-api:1.0-MR1'
    compile 'javax.xml.bind:jaxb-api:2.3.0'

    wsdl2java 'javax.xml.bind:jaxb-api:2.3.0'
    wsdl2java 'com.sun.xml.bind:jaxb-ri:2.3.0'
    wsdl2java 'com.sun.xml.bind:jaxb-xjc:2.3.0'
    wsdl2java 'com.sun.xml.bind:jaxb-core:2.3.0'
    wsdl2java 'com.sun.xml.bind:jaxb-impl:2.3.0'

    wsdl2java 'javax.xml.ws:jaxws-api:2.3.0'
    wsdl2java 'javax.jws:jsr181-api:1.0-MR1'

    wsdl2java 'org.apache.cxf:cxf-tools-wsdlto-core:3.4.5'
    wsdl2java 'org.apache.cxf:cxf-tools-wsdlto-frontend-jaxws:3.4.5'
    wsdl2java 'org.apache.cxf:cxf-tools-wsdlto-databinding-jaxb:3.4.5'

    implementation 'javax.annotation:javax.annotation-api:1.3.2'
    annotationProcessor("javax.annotation:javax.annotation-api:1.3.2")
}

def wsdl2java = task generateJavaFromWsdl(type: JavaExec) {
    String wsdl = 'src/main/resources/wsdl/CarServices.wsdl'
    String genSrcDir = "${projectDir}/build/generated-sources/CarServices"

    inputs.file wsdl
    outputs.dir genSrcDir

    classpath configurations.wsdl2java
    main "org.apache.cxf.tools.wsdlto.WSDLToJava"

    args '-encoding', 'UTF-8', '-d', genSrcDir, wsdl

    OutputStream baos = new ByteArrayOutputStream()
    errorOutput = new OutputStream() {
        void write(int b) {System.err.write(b); baos.write(b) }
        void flush() { System.err.flush(); baos.flush() }
        void close() { System.err.close(); baos.close() }
    }

    doLast {
        def str = baos.toString()
        if (str.contains('Usage : wsdl2java') || str.contains('WSDLToJava Error')) {
            throw new TaskExecutionException(tasks[name],
                    new IOException('Apache CXF WSDLToJava has failed. Please see System.err output.'))
        }
    }
}
compileJava.dependsOn += wsdl2java
sourceSets.main.java.srcDirs = ['src/main/java', 'build/generated-sources/CarServices']

Getting below error while building and NO Java binding classes got created

Caused by: java.lang.ClassNotFoundException: javax.annotation.Resource

Upvotes: 2

Views: 7235

Answers (1)

Balaji211
Balaji211

Reputation: 307

Answering my own question as it may help someone else. Below "build.gradle" config works with Java 11.. It creates required Java binding classes along with port class (Interface) also.. Reference links are attached.

https://ciscoo.github.io/cxf-codegen-gradle/docs/1.0.0-rc.3/user-guide/

    buildscript {
    repositories {
        mavenCentral()
        jcenter()
    }
}

plugins {
    id 'org.springframework.boot' version '2.6.2'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
    id "io.mateo.cxf-codegen" version "1.0.0-rc.3"
}

apply plugin: 'groovy'
apply plugin: 'java'

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

sourceCompatibility = '11'
targetCompatibility = '11'

repositories {
    mavenCentral()
}


dependencies {
    implementation 'org.springframework.boot:spring-boot-starter'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    
    implementation 'org.springframework.boot:spring-boot-starter-web-services'
    
    implementation 'org.codehaus.groovy:groovy-all:3.0.2'
    
    cxfCodegen "jakarta.xml.ws:jakarta.xml.ws-api:2.3.3" 
    cxfCodegen "jakarta.annotation:jakarta.annotation-api:1.3.5" 
    implementation 'javax.jws:javax.jws-api:1.1'
}

cxfCodegen {
    wsdl2java {
        example {
            wsdl = file("${projectDir}/src/main/resources/wsdl/BLZService.wsdl")
            outputDir = file("${buildDir}/generated-java") 
            markGenerated = true
        }
    }
}

compileJava.dependsOn wsdl2java


test {
    useJUnitPlatform()
}

Upvotes: 4

Related Questions