On 16/12/2011, at 5:48 AM, gavares wrote:
> I've been wrestling with this for about a day now. I'm attempting to invoke a
> build.xml file from a gradle script and the build.xml in question has a
> taskdef for com.oopsconsultancy's XmlTask. The build.xml runs fine when
> invoked via ant. Invoking from build.gradle fails because it cannot find the
> class for XmlTask. My build.gradle:
> configurations {
>
> antcp {
>
> description = 'ant classpath'
>
> transitive = true
>
> exclude module: 'ant'
>
> }
> }
>
> dependencies {
> antcp "ant-contrib:ant-contrib:1.0b3"
>
> antcp "com.oopsconsultancy:xmltask:1.16"
>
> }
>
>
>
> task gradleDist << {
> println "PATH: ${configurations.antcp.asPath}"
>
> ant.taskdef resource: "net/sf/antcontrib/antcontrib.properties",
>
> classpath: configurations.antcp.asPath
>
> ant.taskdef(name: 'xmltask', classname:
> 'com.oopsconsultancy.xmltask.ant.XmlTask', classpath:
> configurations.antcp.asPath)
> ant.ant antfile: "build.xml", target: "dist", dir: "."
>
> ant.ant antfile: "build.xml", target: "build-dist-artifact", dir: "."
Each Gradle project has an Ant project associated with it, and when you run an
Ant task, that task runs against the associated Ant project. However, Ant's
<ant> task actually runs the build in another project, which won't be able to
see the taskdefs you've done here (taskdefs won't be inherited). You can either:
1. Drive Ant programatically to inject the classpath into Ant's 'system'
classloader.
2. Inject the classpath into the Ant script, for use in a taskdef in there:
in Gradle:
ant.properties['antcontrib.classpath'] = configurations.antcp.asPath
in build.xml:
<taskdef ... classpath="${antcontrib.classpath}"/>
3. Import the ant script, and treat 'dist' and 'build-dist-artifact' as regular
Gradle tasks:
in Gradle:
ant.taskdef(....)
ant.importBuild('build.xml')
task gradleDist(dependsOn: 'dist', 'build-dist-artifact')
>
> }
> When building, the ant path is printed as:
> /home/builder/.gradle/caches/artifacts-4/ant-contrib/ant-contrib/76dd5c26956e9373dcceb581ac0cfb1c/jars/ant-contrib-1.0b3.jar:/home/builder/.gradle/caches/artifacts-4/com.oopsconsultancy/xmltask/76dd5c26956e9373dcceb581ac0cfb1c/jars/xmltask-1.16.jar
> So I can see that xmltask is on my ant classpath but the build script fails
> with the following error:
> taskdef class com.oopsconsultancy.xmltask.ant.XmlTask cannot be found
> using the classloader AntClassLoader[]
> The build.xml has a taskdef for XmlTask like:
> <taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask"/>
> Not sure what I'm doing wrong.
> View this message in context: Multi-project Ant build and XmlTask
> Sent from the gradle-user mailing list archive at Nabble.com.
--
Adam Murdoch
Gradle Co-founder
http://www.gradle.org
VP of Engineering, Gradleware Inc. - Gradle Training, Support, Consulting
http://www.gradleware.com