Maybe I’m not understanding what you’re trying to do, but it seems that you are 
not using the taskdef defined in your gradle script.  You’re doing this:



ant.ant antfile: "build.xml", target: "dist", dir: "."
ant.ant antfile: "build.xml", target: "build-dist-artifact", dir: "."

Which just invokes the ant targets defined in your ant build script, which, I 
believe, is totally unrelated to the taskdef defined before it.  So if those 
ant targets are attempting to call your taskdef, the taskdef (with classpath) 
would have to be defined in build.xml.  Instead, I would think you should do 
this:

ant.taskdef(name: 'xmltask', classname: 
'com.oopsconsultancy.xmltask.ant.XmlTask', classpath: 
configurations.antcp.asPath)
ant.xmltask(requiredAttr1: 'value1', requiredAttr2: 'value2') {
      fileset(dir: 'src/main/java', includes: '**/*.xml')
      ...
anyRequiredSubelement(subattr1: subvalue1, subattr2: subvalue2)
}

Which directly invokes the taskdef xmltask defined in gradle without the need 
for any external ant script.  Sorry for my pseudo-code, I don’t know anything 
about the specific task you’re using.

I do something similar on my project with XmlBeans 
(org.apache.xmlbeans.impl.tool.XMLBean) and JBoss WSConsume 
(org.jboss.wsf.spi.tools.ant.WSConsumeTask), and never had any problems.  It’s 
a nice feature in gradle to be able to run custom ant tasks without any ant 
scripts.

Hope that helps…

From: gavares [mailto:[email protected]]
Sent: Thursday, December 15, 2011 1:48 PM
To: [email protected]
Subject: [gradle-user] Multi-project Ant build and XmlTask

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: "."

}
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<http://gradle.1045684.n5.nabble.com/Multi-project-Ant-build-and-XmlTask-tp5078402p5078402.html>
Sent from the gradle-user mailing list 
archive<http://gradle.1045684.n5.nabble.com/gradle-user-f1431424.html> at 
Nabble.com.



Andrew Goode |   Technical Architect/Team Lead

[email protected]<mailto:[email protected]>

tel 678-762-6861

1200 Lake Hearn Drive, Suite 500, Atlanta, GA  30319

www.nextraq.com<http://www.nextraq.com>


[cid:[email protected]]




This communication, along with any attachment(s), is intended only for the use 
of the addressee(s) and may contain proprietary, confidential or privileged 
information. If you are not the intended recipient, you are hereby notified 
that any dissemination, distribution or copying of any information contained in 
or attached to this communication is strictly prohibited. If you have received 
this message in error, please notify the sender immediately and destroy the 
original communication and its attachments without reading, printing or saving 
in any manner. Thank you.


<<inline: 09f462.png>>

Reply via email to