Missing classpath in custom task with ant

I am trying to create a custom task which is supposed to extend XJCTask task and invoke it to generate classes from provided wsdl file. Wort noting is that it works beautifully when defined in this manner:

task generateCardData {
    ext.sourcesDir = "${projectDir}/src/main/java"
    ext.classesDir = "${buildDir}/classes/main"
    ext.schema = "${projectDir}/wsdl/myWsdl.wsdl"

    outputs.dir classesDir

    doLast() {
        project.ant {
            taskdef name: "xjc", classname: "com.sun.tools.xjc.XJCTask",
                    classpath: configurations.jaxb.asPath
            mkdir(dir: sourcesDir)
            mkdir(dir: classesDir)

            xjc(destdir: sourcesDir, schema: schema,
                    package: "<package-of-generated-classes>") {
                arg(value: "-wsdl")
                produces(dir: sourcesDir, includes: "**/*.java")

            javac(destdir: classesDir, source: 1.8, target: 1.8, debug: true,
                    debugLevel: "lines,vars,source",
                    classpath: configurations.jaxb.asPath) {
                src(path: sourcesDir)
                include(name: "**/*.java")
                include(name: "*.java")

            copy(todir: classesDir) {
                fileset(dir: sourcesDir, erroronmissingdir: false) {
                    exclude(name: "**/*.java")

However this task can be made generic by passing String parameters for “< package-of-generated-classes >” and ext.schema.
This is how I tried to implement it:

class GenerateModelFromWSDL extends DefaultTask {
    String wsdlPath = ""
    String destinationPackage = ""
    File sourceDir
    File buildDir
    AntBuilder antBuilder

    public GenerateModelFromWSDL() {
        sourceDir = getProject().file("/src/main/java")
        buildDir = getProject().file("/build/classes/main")
        antBuilder = getProject().getAnt()

    def runMe() {
        ext.sourcesDir = sourceDir
        ext.classesDir = buildDir
        ext.schema = wsdlPath

        ant.taskdef(name: "xjc",
                classname: "com.sun.tools.xjc.XJCTask",
                classpath: getProject().configurations.jaxb.asPath)

        ant.mkdir(dir: ext.sourcesDir)
        ant.mkdir(dir: ext.classesDir)

        ant.xjc(destdir: ext.sourcesDir, schema: ext.schema, package: destinationPackage) {
            arg(value: "-wsdl")
            produces(dir: ext.sourcesDir, includes: "**/*.java")
        ant.javac(destdir: ext.classesDir,
                source: 1.8,
                target: 1.8,
                debug: true,
                debugLevel: "lines,vars,source",
                classpath: getProject().configurations.jaxb.asPath) {
            classpath {
                fileset dir: buildDir
                fileset dir: getProject().file("/libs")

            src(path: ext.sourcesDir)
            include(name: "**/*.java")
            include(name: "*.java")

        ant.copy(todir: ext.classesDir) {
            fileset(dir: ext.sourcesDir, erroronmissingdir: false) {
                exclude(name: "**/*.java")

This results in following output:

[ant:javac] : warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
[ant:javac] C:\path_to_file\Application.java:3: error: package org.springframework.boot does not exist
[ant:javac] import org.springframework.boot.SpringApplication;

So it looks like ant does not see a project’s classpath/libraries that are supposed to be passed to javac. Can you tell me what am I doing wrong and how should I fix it?

1 Like

What dependencies are specified in your “jaxb” configuration?

Please did you find solution to your problem because i have the same.