Failing to load antContrib taskdefs

(davidmichaelkarr) #1

I’m trying to experiment with migrating a messy set of Ant scripts to Gradle. Just importing the “build.xml” failed, because I already had a “build” task defined. I then tried to follow the steps in for hacking around task conflicts.

For background, I have a “build.xml” which imports another build script in an external directory, which was provided to us (this is from ATG, which you don’t really need to know).

In my “build.xml”, I have the following: ------------------

<property name="global.dir" value="${store.root.dir}"/>
  <import file="${global.dir}/buildtools/common.xml"/>

That “common.xml” file has some taskdefs, which I’m to understand don’t transfer well when importing Ant build scripts into Gradle. So, I’m stepping through them now.

The first one I have to deal with in the “common.xml” file is this: ----------------

<taskdef resource="net/sf/antcontrib/"

In my “commonBuild.gradle” file, I’ve added the following for this: ---------------------------

out.println "storeRootDir[" + storeRootDir + "]"
ant.taskdef(resource: 'net/sf/antcontrib/') {
        classpath {
            fileset(dir: storeRootDir + '/buildtools/lib', includes: 'ant-contrib.jar')

When I run the build, I see this: -------------------------

[ant:taskdef] Could not load definitions from resource net/sf/antcontrib/ It could not be found.

I’ve verified that “C:/ATG/ATG10.2/CommerceReferenceStore/Store/buildtools/lib/ant-contrib.jar” has “net/sf/antcontrib/”.

What might I be doing wrong?

(Perryn Fowler) #2

Remember that the gradle code just generates calls to the ant api. It is not clear to me from looking at the ant documentation how ant will treat include patterns that contain no wildcards, so that may be your problem.

In any case the ant xml you showed uses ‘classpath’ as an attribute rather than a nested element, so the following is more similar to your original ant, and also avoids includes.

ant.taskdef(resource: 'net/sf/antcontrib/',
               classpath: storeRootDir + '/buildtools/lib/ant-contrib.jar')

(davidmichaelkarr) #3

This change didn’t appear to make any difference.

I also thought to try running with “-d”, and that produced output that is even more confusing. Well before the “Could not load definitions …” line, I saw a number of lines like this:

10:04:57.838 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] Finding class net.sf.antcontrib.platform.ShellScriptTask
10:04:57.838 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] Loaded from C:\ATG\ATG10.2\CommerceReferenceStore\Store\buildtools\lib\ant-contrib.jar net/sf/antcontrib/platform/ShellScriptTask.class
10:04:57.843 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] Finding class
10:04:57.844 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] Loaded from C:\ATG\ATG10.2\CommerceReferenceStore\Store\buildtools\lib\ant-contrib.jar net/sf/antcontrib/property/PropertyCopy.class
10:04:57.845 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] Finding class
10:04:57.845 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] Loaded from C:\ATG\ATG10.2\CommerceReferenceStore\Store\buildtools\lib\ant-contrib.jar net/sf/antcontrib/property/AbstractPropertySetterTask.class
10:04:57.968 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] Loaded from C:\ATG\ATG10.2\CommerceReferenceStore\Store\buildtools\lib\ant-contrib.jar net/sf/antcontrib/design/Log.class

What I’m realizing now is that the “Could not load …” error isn’t coming from this taskdef, it’s coming from when I try to import the “common.xml” Ant build script from my Gradle build script. I just tried commenting out that “ant.importBuild” line, and the build doesn’t give me that error from the taskdef (is also fails to do anything useful, as most of the critical targets are defined in that “common.xml” file).

It’s seeming like there are some situations where the import of the Ant build script into Gradle doesn’t just magically do the right thing. I may have to hand-code in Gradle everything that’s done in that “common.xml” file.