Gradle Plugin: Invoke ANT task


I’m currently migrating a Gradle plugin that was written in Groovy to Java.

In that plugin I have a task that uses ANT functionality to create a JUnit test report.

Within the task action the Groovy plugin does the following:

        project.ant.junitreport(todir: mergedResultsDir) {
            fileset(dir: resultsDir, includes: '**/*.xml')
            report(toDir: reportsDir, format: 'frames')

Can I replicate that in Java or do I have to fall back to Groovy for that one task?

Have a look for example at how to do it.

I fail to understand where the classpath comes from.

I do understand that the plugin needs to bring the ant jar for the optional dependency ( org.apache.ant:ant-junit:1.9.7 in this case), but I always get the following error when running the task:

> Problem: failed to create task or type junitreport
  Cause: the class was not found.
          This looks like one of Ant's optional components.
  Action: Check that the appropriate optional JAR exists in
          -the IDE Ant configuration dialogs
  Do not panic, this is a common problem.
  The commonest cause is a missing JAR.
  This is not a bug; it is a configuration problem

It doesn’t matter if my plugin declares the dependency as implementation, api, compileOnly or compileOnlyApi.
In the old groovy plugin it worked with runtime, but that is deprecated now

but that is deprecated now

It is deprecated since many many many years already. :smiley:
The old runtime is like the new runtimeOnly.
But if implementation and api which also do land on the runtimeClasspath do not work, neither runtime nor runtimeOnly would help.

The general documentation about using Ant from Gradle is at Using Ant from Gradle.
For how to use it from Java I showed you the example from Gradle sources.

If you need more help, you at least have to share an MCVE. :slight_smile: