Unable to use ant.junitreport task even though ant-junit jar is present

I’m trying to call ant.junitreport. Gradle can’t find org.apache.tools.ant.taskdefs.optional.junit.XMLResultAggregator even though ant-junit.jar is present in ANT_HOME/lib. Tried dropping the jar file into GRADLE_HOME/lib but still doesn’t work. Also tried using ant.project.addTaskDefinition to bind XMLResultAggregator but that doesn’t work either. Any suggestions?

I’m using gradle 1.0-milestone-8 with groovy 1.8.6.

Upgrading to the latest versions of Gradle (1.0-rc-3) and ant (1.8.3) made no difference.

Hello, to add the ant-junit.jar to your classpath to have to add it directly to the ant-classloader:

repositories{
 mavenCentral()
}
  configurations {
   antClasspath
 }
   dependencies {
   antClasspath 'org.apache.ant:ant-junit4:1.8.3'
 }
   ClassLoader antClassLoader = org.apache.tools.ant.Project.class.classLoader
 configurations.antClasspath.each { File f ->
   antClassLoader.addURL(f.toURI().toURL())
 }

I hope that helps, René

Yes, that fixed it. Thanks. I’m curious why I need to explicitly add it to the classpath. The gradle console error message implies it should be found if the jar is in the right place.

The error message, that shows up is directly coming from ant and explains the error situation from an ant users point of view. Maybe gradle should do a better job here and give a better, more helpful error message here.

I certainly wrapped myself around the axle for awhile :-).

Once I got it working I discovered two subtleties with ant.junitreport:

  1. Ant tasks run at configuration time, not execution time (makes sense when you think about it). Since junitreport’s input files aren’t ready yet, I had to wrap it in a doLast closure.

  2. Tried to put ant.junitreport inside a Gradle task that got executed inside afterSuite. Got errors stating “Cannot start long running operation, as the task artifact state cachs has not been locked”. If I put the ant.junitreport statement directly inside afterSuite, all is fine. Or if I have its enclosing task depend on my test task, everything is also fine.

@Rene

I realize this is an old post…perhaps you’ll still get it. Did you put this in the build script, in subproject, all projects, or in the base part of the root build script?

I’m unable to get this working, and am quite desperate.