I'm generating a web service client via a gradle build. In order to compile
my client, I need to first generate the stubs using the wsimport task. The
problem I'm having is that by running the wsimport task before the compile
task, the build fails if the destination directory doesn't already exist.

My build file is below. I have a "sourceSets" task to map my project
structure to a standard Eclipse structure. When running the wsimport task,
the compiled code is supposed to go into the standard build directory, which
here is designated as sourceSets.main.classesDir.  My problem is that I
apparently need to create the build/main/classes directory ahead of time, or
the wsimport task fails.

Am I doing something wrong here? I'm accustomed to the build artifacts being
generated automatically.

(Btw, this sample accesses the Global Weather web service at the URL listed,
just as a simple example.)

apply plugin:'groovy'
apply plugin:'eclipse'

repositories {
    mavenCentral()
    mavenRepo urls:["http://download.java.net/maven/1";,
        "http://download.java.net/maven/2";]
}

configurations {
    jaxws
}

sourceSets {
    main {
        java { srcDirs = [] }
        groovy { srcDir 'src' }
    }
    test {
        java { srcDirs = [] }
        groovy { srcDir 'test' }
        resources { srcDir 'resources' }
    }
}

task wsimport(dependsOn: processResources)  {
    doLast{
        ant {
            taskdef(name:'wsimport',
                classname:'com.sun.tools.ws.ant.WsImport',
                classpath:configurations.jaxws.asPath)
            wsimport(keep:true,
                destdir: sourceSets.main.classesDir,
                sourcedestdir:'src',
            wsdl:'http://www.webservicex.net/GlobalWeather.asmx?wsdl')
        }
    }
}
wsimport.onlyIf { !(new File('src/net/webservicex')).exists() }
compileJava.dependsOn(wsimport)

def groovyVersion = '1.7.8'
def spockVersion = '0.5-groovy-1.7'

dependencies {
    groovy "org.codehaus.groovy:groovy-all:$groovyVersion"
    jaxws 'com.sun.xml.ws:jaxws-tools:2.1.4'

    testCompile "org.spockframework:spock-core:$spockVersion"
}

Thanks for any assistance. This is going to go into my SOAP web services
chapter of my book "Making Java Groovy", currently available in MEAP form
from http://manning.com/kousen . I've been checking through the code and
realized I had a problem here when I started from scratch, rather than
running from my existing project.

Ken Kousen
-- 
Kenneth A. Kousen
President
Kousen IT, Inc.

Email: [email protected]
Site: http://www.kousenit.com
Blog: http://kousenit.wordpress.com
Twitter: @kenkousen
Making Java Groovy<http://affiliate.manning.com/idevaffiliate.php?id=1084_254>

Reply via email to