Convert task from Groovy to Java


I’m converting Gradle plugins written in Groovy to Java. I have some tasks using ant, e.g.:

ant.taskdef(name: "wsimport", classname: "", classpath: wsimportClasspath)
  package: packageName,
  sourcedestdir: genJaxbDir,
  wsdl: wsdlFile.toURI()

How I can translate this to DefaultTask using Java? I have access to AntBuilder in my task and I can do something like that:

AntBuilder ant = getProject().getAnt();
ant.invokeMethod("echo", "hello, world!");

What I don’t understand, how I can add Ant task definition with name, classpath, parameters etc.

I solved this using JavaExec task (instead of DefaultTask) with following configuration:

// don't forget to set correct 'workingDir' and 'args'