I’m a complete gradle newbie and I’m trying to import an ant file and invoke one of it’s targets that happens to do some junit stuff. Apparently I’m loading up the taskdef properly but I’m clueless.
Gradle uses its own ‘instance’ of ant and does not bother using what’s installed at $ANT_HOME, yes?
Thanks for the reply, Luke. I’ve been meaning to get this sample into a github repo for easy troubleshooting but in the mean time, here’s what my ant target looks like. In a nutshell, I’m just trying to call a target that runs some unit tests via junit.
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.
I’m trying to wrap my ant build.xml file which uses junit and i tried your solution and I get this error:
Could not resolve all dependencies for configuration ‘:junitAnt’. . . .
I believe this is because the taskdef is being called in the configuration phase (dependencies have not been resolved yet). Any ideas on how to fix this?
I have a multi-project build and have an artifactory repo setup. All of my subprojects are able to resolve the dependencies except for this one… not exactly sure why. Although this is the only one where I’m wrapping an ant script like this. I did redefine the repo in my subproject’s build.gradle file and it seems to resolve the dependencies fine.
I was curious though and went back removed the respository definition from my subproject’s build script. I added the taskdef to an execution task and it was able to resolve just fine. I’m guessing this might be a bug with the artifactory plugin?
I’d have to see your build code to get an idea of what’s going wrong. If you want to discuss this further, please open a question and post/link your source code.
Benjamin: did you put this in the buildscript section? The place where I’ll be calling the JUnit task is defined in the subproject section. Is that the correct place to put this code instead if not the buildscript section
I would include my code if it wasn’t so confusing… I think it would do more harm than good at this point. However…
It seemed to me that running Ant tasks would be part of the “build” code, and therefore would use the buildscript block. I’ve put your examples in my subproject block, and made considerable progress.
My last step… I’m running tests in the Subproject, but my Test classes (compiled… thus the Ant task instead of a Test task) reside in the root project. I’d like to be able to reuse the jar sitting in the libs directory of the root project for all the subprojects. So I need to reference (I believe) a fileTree in {rootDir}/libs to make the test jar available. Does this make senses?
I really appreciate the help. I was banging my head before seeing your code snippets.