JUnit is an optional task in Ant. Usually, you add the JUnit library and the library containing the JUnit task to Ant’s lib directory to make it work. Gradle ships with Ant and uses the Ant libraries contained in the Gradle distribution. Gradle does not come with the JUnit task so you need to declare it in your build script.
To reuse an Ant task that uses the JUnit task, you will have to declare the Ant task definition in Gradle. The following example shows how to retrieve the JUnit libraries from Maven Central by assigning them to a custom configuration.
repositories {
mavenCentral()
}
configurations {
junitAnt
}
dependencies {
junitAnt 'junit:junit:4.8.2'
junitAnt('org.apache.ant:ant-junit:1.9.2') {
transitive = false
}
junitAnt('org.apache.ant:ant-junit4:1.9.2') {
transitive = false
}
}
ant.taskdef(name: 'junit', classname: 'org.apache.tools.ant.taskdefs.optional.junit.JUnitTask',
classpath: configurations.junitAnt.asPath)
ant.importBuild 'build.xml'