I'm porting an Ant build.xml to Gradle. I wanted to use Gradle's AntBuilder to do something like
task mytask << {
ant {
jar(..) { ... }
}
}
I am having some trouble with the syntax and can't figure out where AntBuilder is documented. The Gradle user guide just points to the API [1] which is pretty useless. As it doesn't document any of ant-tasks supported by AntBuilder (e.g. jar, copy, etc.).
Googling I found another person asking the same question [2] but no one answered.
[1] http://www.gradle.org/docs/current/groovydoc/org/gradle/api/AntBuilder.html
[2] http://groovy.329449.n5.nabble.com/Where-s-the-documentation-for-Antbuilder-tt2857050.html#none
AntBuilder is documented in the "Using Ant from Gradle" chapter of the Gradle User Guide. That said, here are some further pointers:
Gradle's AntBuilder is (virtually) the same as Groovy's AntBuilder. The syntax is a mechanical translation of the Ant XML syntax. To get started, check out the samples in the full Gradle distribution.
AntBuilder can be used with any Ant task. For information on a particular Ant task, check its documentation.
Third-party Ant tasks (i.e. Ant tasks that don't ship with Ant) have to be defined beforehand exactly as in Ant. For details, see the user guide chapter.
Related
I'm starting to work on pipelines for jenkins (formerly workflow)
I'm using IntelliJ for an IDE
Is there a source of Documentation for GDSL or some way I can know what groovy is acceptable in the pipeline and what is not?
Also is there a way that I can test run the GDSL before having to check in my Jenkinsfile?
Is there a source of Documentation for GDSL
Yes, as of 1.13 you can download a GDSL schema from Snippet Generator and install it in IDEA. There are some aspects missing—for example step return types are not defined in this schema. Last I checked it also did not offer completion on, for example, known $class implementations for step; this information is available in the Snippet Generator UI and downloadable HTML reference documentation.
is there a way that I can test run the [script?] before having to check in my Jenkinsfile?
There is not currently an offline test feature; it would be tricky since everything in a Pipeline script is intended to be interacting with a live Jenkins service. (If you have other logic in there, it would be better factored out into external scripts in the language of your choice.)
As of 1.14 there is a Replay link you can use to iteratively test proposed changes before committing to Jenkinsfile, and you can use this from the CLI too.
I haven't been able find an Ant task that works out of the box with ANTLR4. I want to be able to invoke options like -visitor to generate the *Visitor interfaces and classes. I suppose I could 'fake it' using the Java task.
You shouldn't need one. Take a look at the build script I use for the grammars in ANTLRWorks 2.
Downloads the correct version of the tool on-demand (so it doesn't have to be included in source control).
Only rebuilds grammars if they are out-of-date.
Builds grammars in parallel for improved build times.
https://github.com/sharwell/antlrworks2/blob/master/org-antlr-works-editor/build.xml
I am using Ant files for build
The build itself is done by IBM Rational Team Concert (RTC) with the help of this Ant file.
My problem is that if I make a mistake in the build XML itself like wrongly typed attribute name, this itself is detected by RTC after loading the files from source control (normally 15-20 mins)
Is there a way to verify (validate) the Ant XML file itself?
There is no schema for an Ant XML. As explained in the FAQ an incomplete DTD can be created but will not work:
An incomplete DTD can be created by the 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
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 and tasks, there are two XML
elements named test (the task and the nested child element of )
with different attribute lists. This problem cannot be solved; DTDs
don't give a syntax rich enough to support this.
Again, the FAQ states the DTD is not (yet?) powerful enough to do this, but I found a preliminary work for Ant 1.6 based on Michel Casabianca's work at the AntDTD page on the Ant Wiki. As for me, I do not intend to use it.
I have some hudson servers for our CI process.
The build tasks use Ant scripts and also old-school *.bat files.
What do you prefer? What are the pros and cons?
(I think of readability, familiarity to developers and extensibility...)
Are there any other options? We have .Net, Java and PHP apps to test.
Batch is a programming language (and not a very good one at that). Ant is a dependency matrix language. What's the difference?
In a programming language, you specify the order everything occurs in. You're responsible to say what is built and the order.
In a dependency matrix language, you merely state the dependencies, and the program figures out what to do and the order it should be done in. One of the biggest issues developers have with Ant or Make is to try to force a build order instead of letting the build system take care of it.
Builds should always be done with a dependency matrix language like Ant.
Let Ant determine what needs to be built and the order it should be built. Don't use Batch. If you're using Batch scripts to call a bunch of Ant script in the order you think they should be called, you're doing it wrong. Have a master Ant script do it and use <subant> calls. Let Ant do the tricky stuff.
You can use batch script to do preliminary work (such as setting ANT_OPTS if Ant needs more memory, or setting environment variables like ANT_HOME and JAVA_HOME and your %PATH% variable to make sure you're using the correct Java and Ant versions. In Hudson, you can set all of this in the Hudson job itself, so you don't have to call the Batch script.
*.bat files pretty much restrict you to dos/windows, like how shell scripts are for linux, whereas Ant/Maven is cross-platform and gives you the option to use a non-Windows CI server
I would like to simplify my main build scripts, and I'd like to have the ability to reuse certain common ant tasks as a library, but I'd also like them to be easily available as a package.
For instance, I've got a task which sets up the Flex environment variables that I need to build a variety of projects. I can (And am currently) include those scripts by relative path from another location in source control. But what I want to do is make a single download-able package that I can grab via Ivy that contains all of these generic tasks.
A jar seems the most natural solution, since this is doable from java (Use the class loader to access the file inside the jar.), but I can't seem to find a "native" way in Ant to just get the xml file.
In short, I want to do:
<import file="some.jar!bootstrap.xml">
But that doesn't work.
Is there someway to do this? Any other suggestions for making a library of ant scripts would be much appreciated as well.
From what I understand you're trying to extract a file containing more ant tasks from your jar and then tell ant to execute the tasks in those extracted files. Since the files are static, you'd probably be better off creating actual java Task definitions in your jar and declaring them in your ant build file. However, if you don't want to do that, you can just use the Unzip ant task to extract the resource out of the jar and onto the file system and then use the Ant task to execute the extracted file.
IIRC there's ongoing work in Ant to support this but it's not supported in any published version.