How to generate artifacts from WSDL and XSD using gradle?

Can you post sample code to generate artifacts from wsdl and xsd using gradle? Also are there any in built plugins available? Also how can we load custom binding files using gradle?

The last time I looked there weren’t any plug-ins and we had to implement our own. Basically we used Java’s xjc to generate stubs. In our first iteration, generated stubs were put in a separate subproject that our main project depends on.

Some code snippets:

task generateJavaFromWsdl(type: Exec) {
 group = 'wsdl'
 executable = 'xjc'
    inputs.file config.wsdlFile
 outputs.dir config.javaDir
    doFirst {
  config.javaDir.mkdirs()
  args '-wsdl'
  args config.wsdlFile
  args '-d', config.javaDir
    }
}

Our implementation was complicated because we have a large number of dependent WSDLs, resulting in a large number of projects. In STS the majority of our projects were for generated which was a problem.

We resolved this by generating a different jar for each service in one project. We then created an artifact definition for each jar:

def services = ['service1', 'service2']
artifacts {
 services.each {service->
  add(service, tasks."jar${service}WebService")
 }
}

The project dependency was set up as:

compile project (path: ':stubsProject', configuration: "service1")
 compile project (path: ':stubsProject', configuration: "service2")

There’s a lot more glue to getting this to work, but for us it was a nice solution.

You could try this 3rd-party gradle-wsdl-plugin https://github.com/jacobono/gradle-wsdl-plugin