How come there is no Apache Ant xml schema definition or DTD for build scripts?
Could please anybody explain to me why is that? I've been always using Maven and absence of xml definition for Ant build script is something that makes me searching through internet and documentation instead of one look at the xsd or DTD.
For instance it is almost impossible to find out whether target d开发者_开发百科efinition can have own property declared or not.
There is a FAQ for this:
Is there a DTD that I can use to validate my build files?
An incomplete DTD can be created by the
<antstructure>
task - but this one has a few problems:
- It doesn't know about required attributes. Only manual tweaking of this file can help here.
- It is not complete - if you add new tasks via
<taskdef>
it won't know about it. See this page by Michel Casabianca for a solution to this problem. Note that the DTD you can download at this page is based on Apache Ant 0.3.1.- It may even be an invalid DTD. As Ant allows tasks writers to define arbitrary elements, name collisions will happen quite frequently - if your version of Ant contains the optional
<test>
and<junit>
tasks, there are two XML elements named test (the task and the nested child element of<junit>
) with different attribute lists. This problem cannot be solved; DTDs don't give a syntax rich enough to support this.
You can also use the ant target:
<target name="dtdgen">
<antstructure output="ant.dtd"/>
</target>
to generate an "ant.dtd" file for your build.xml directly. Just add the target to your script and execute "ant dtdgen".
(*Chris*)
I read somewhere that it is impossible to create a schema for ANT because ANT is not a sufficiently regular grammar. You can test it for conformance with vanilla XML grammar if you use Stylus Studio.
You might also feed some of your working scripts into Stylus Studio and ask it to generate an XSD. Then polish the XSD manually. That would not be full ANT, but it might help catch errors.
My way of handling the problem is not to write ANT XML directly, but to generate it with a stomper program. That way it is guaranteed to be correct once I get the program correct. It is then perfectly consistent across all projects.
see https://wush.net/websvn/mindprod/filedetails.php?repname=mindprod&path=%2Fcom%2Fmindprod%2Fzzz%2FMkAnt.java
for my own stomper code.
精彩评论