Is it really necessary to use ant.java to run a java project with arguments?

I am working on a project that auto-generates some code as part of the build process. The code generation tool takes some arguments to specify inputs/outputs/options, and it is also being built with gradle, i.e. it is part of the overall project structure.

In order to use the tool I have had to write this ugly thing in the project that should be built from autogenerated code:

task generateSourceManual() {
    def dmlFile = project(':tlm-war').projectDir.toString() + "/WEB-INF/datamodel.dml"
    def installedCodeGenJar = project(':codegen').buildDir.toString() + "/install/codegen/lib/codegen.jar"

    outputs.file("$buildDir/generated/")
    doLast {
        ant.java(jar: installedCodeGenJar, fork: true) {
            arg(value: "genrest")
            arg(value: "$dmlFile")
            arg(value: "$buildDir/generated")
        }
    }
}

generateSourceManual.dependsOn project(':comandr-codegen').installDist
generateSourceManual.dependsOn clean
compileJava.dependsOn generateSourceManual

My concerns are the following:

  1. I have to use “installDist” on the code generation tool, otherwise I can’t get ant.java to work
  2. I cannot use a JavaExec task- no matter what I tried, gradle says that it cannot run the command due to some FileNotFoundException. However, if I copy the exact command that it runs into a terminal and run it there it runs just fine.
  3. I cannot use an Exec task either where I manually invoke java. I run into the same problems. Regardless of whether I use java -jar or with -cp.

This looks like a ugly hack/workaround, but for now it works. I wasted a stunning 6-7 hours on this, just because something simple such as running another java project in the same fricking gradle project is completely impossible without resorting to ant.java.