Out of memory on multiple wsimport ant task executions - how to work around?

Hi everyone,

Here’s my problem: I have a big and deep gradle multiproject build that contains lots of WSDL interface definitions. I want to ensure the validity of all wsdl files in every project. To do so, I use the JAX-WS wsimport ant task for generating bindings. This task fails if the wsdl / xsd files contain errors.

configurations {
            wsImport
        }
          dependencies {
            wsImport (group: 'com.sun.xml.ws', name: 'jaxws-tools', version: '2.1.4')
        }
          task validateWsdl(dependsOn: otherTask) {
            ext.generatedWsdlDir = file("${project.buildDir}/tmp/wsimport/")
            doLast {
                ant.taskdef(name: 'wsimport',
                            classname: 'com.sun.tools.ws.ant.WsImport',
                            classpath: configurations.wsImport.asPath)
                  otherTask.outputs.files.asFileTree.matching({include '**/*.wsdl'}).each { wsdlFile ->
                    delete(generatedWsdlDir)
                    mkdir(generatedWsdlDir)
                      try {
                        ant.wsimport(keep: false,
                                     destdir: generatedWsdlDir,
                                     wsdl: wsdlFile,
                                     package: 'mypackage.wsdlvalidate',
                                     verbose: false,
                                     fork: false,
                                     xendorsed: true,
                                     xnocompile: true)
                    } catch (Exception e) {
                        throw new RuntimeException("Error validating WSDL file: ${wsdlFile} : ${e.message}", e)
                    }
                      delete(generatedWsdlDir)
                }
            }
        }

This works wonderfully on a single project. When I run it from the root project, however, it fails with: java.lang.OutOfMemoryError: PermGen space. The obvious solution would be to specify “fork: true”. Doing this helps, indeed, but suppresses all console output from the ant task. There are, however, some warnings it outputs on the console, that I want to see in the build log.

Is it possible to achieve this by either fixing what causes the OOM or redirecting the console output from the forked process to the main build process?

Thanks in advance, Mike

According to your description, both permgen usage and output redirection are caused/controlled by the Ant task. The only way you can solve this problem on Gradle’s side is not to fork and to increase the Gradle JVM’s permgen space (e.g. in GRADLE_OPTS).

Isn’t there a way I could easily fork an Ant task with gradle tools and capture its output?

The best you could do is to execute Ant as an external process, with an ‘Exec’ or ‘JavaExec’ task.

Funny thing: when I run the forked variant with --info, I see the ant task’s output on the console. So I think http://issues.gradle.org/browse/GRADLE-1105 might be my solution!

Any workaround known yet?

I don’t know of a way to get this behavior at this time.