Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 20 Next »

How do I get/set ant properties?

To load a properties file: '')

To get a property: 'ivy.local.repository.dir', value: ivyLocalRepoDir)

To set:

  logkitVersion ='logkit.version'

I'd like to use Bazaar to work with Gant - what are my first steps?

If Bazaar is not already installed on your system take a look at this link:

Download Bazaar

The official Gant repository is a Subversion repository so you will need to have bzr-svn installed to use Bazaar. You might want to take a look at this link on how to use it:

Use it

Alternatively, up to date Bazaar branches of Gant Trunk and Gant 1_1_X can be found at:

These are Bazaar branches with no working tree so if you use a browser to view them they will appear empty. However if you branch from them using "bzr branch ...", you will get a branch.

How can I access whether the debug flag is set in my build.gant files?

import org.codehaus.gant.GantState

// We use the Gant State or "-d" flag
// to switch debugging on in our build.
// This closure allows us to query that property
isDebug = { ->
 if (GantState.verbosity == GantState.DEBUG) {
   return true

if (isDebug()) {

I'd like to use the uptodate task from Ant repeatedly in the same Gant.binding, would you provide a reusable approach?

Given that Ant uses immutable properties, the resulting property name will always need to be different otherwise
you will end up returning the same calculated value over-and-over. Try this closure:

isUpToDate = { includeList, excludeList, jar ->
  resultPropName = "result." + System.currentTimeMillis()
  Ant.uptodate(property: "${resultPropName}", targetfile: jar) {
    includeList.each {
      srcfiles(dir: it)
    excludeList.each {
      srcfiles(dir: it, excludes: "*")
  return Boolean.valueOf("${resultPropName}")

How do I set my classpath when calling Gant?

You have two options:  

1) when calling Gant, pass in a -P=classpath parameter:

gant -P ../build/classes:../build/lib/myjar.jar

2) pass in a -L parameter to add in class directories:

gant -L ../build/lib -L ../build/lib/ext -L ../build/out/classes

Can targets take parameters like other closures?

Yes.  Although targets are usually specified like:

where the closure comprising the body of the target appears to have no parameters, in fact there is an implicit parameter it.  When called from the command line it always has the value null but when called from within a Gant script the target closure can be called with a parameter.  For details see Targets and Parameters

  • No labels