0
我想知道如何将groovy脚本变量(此处为compName,compPath)传递给ant目标(这里是:build.application ) 我想在这build.xml文件在ANT任务中使用groovy脚本来调用另一个ant任务并将groovy变量传递给ANT目标属性
<target name="xmlreader" description="Clean deployment directory">
<groovy>
import javax.xml.xpath.*
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
def ant = new AntBuilder()
File buildfile = new File("d:/Users/sk/workspace/build.xml")
fileContent = buildfile.getText()
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(buildfile);
XPathFactory xPathfactory = XPathFactory.newInstance();
XPath xpath = xPathfactory.newXPath();
XPathExpression expr = xpath.compile("BuildConfig/Applications/ApplicationConfig");
NodeList nl = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
for (int i = 0; i < nl.getLength() ; i++) {
String compName = (String)nl.item(i).getElementsByTagName("Name").item(0).getChildNodes().item(0).getNodeValue();
String compPath = (String)nl.item(i).getElementsByTagName("SVN_Path").item(0).getChildNodes().item(0).getNodeValue();
ant.echo "${compName}"
ant.echo "${compPath}"
ant.ant(antfile: 'build.xml'){
target(name: 'build.application')
}
}
</groovy>
</target>
通过系统属性? – Opal 2014-09-11 09:34:29