How to set system properties for an ant task


An ant task needs system properties to be set. I would like to learn how to do it. No matter what I tried all failed with: Cannot get property ‘value’ on null object See my latest try in the code.


task schemaTool << {
    def props = new Properties();
    File f = new File(sourceSets.main.output.resourcesDir, "")
    f.withInputStream { props.load(it) }
    println "Loaded " + props.size() + " local properties"
      ant.taskdef(name: 'schematool',
            classname: '',
            classpath: configurations.jdo.asPath,
      ant.schematool(dir: sourceSets.main.output.resourcesDir, verbose: 'true', mode: 'create', failonerror: 'true') {
        classpath {
            pathelement(location: sourceSets.main.output.classesDir.getPath())
            pathelement(path: configurations.jdo.asPath)
        fileset(dir: sourceSets.main.output.resourcesDir) {
            include(name: '**/*.jdo')
            include(name: '**/*.orm')
  [it.key] = it.value

The original task (excerpt):

<taskdef name="schematool" classname="" />
  <schematool failonerror="true" verbose="true" mode="create">
        <path refid="schematool.classpath"/>
    <fileset dir="${classes.dir}">
        <include name="**/*.jdo"/>
    <sysproperty key="datanucleus.ConnectionDriverName"

you’re setting in your example. I think you have to declare a system property. You can do this by using System.setProperty(key, value) in your gradle script.

cheers, René

Hi Rene,

First of all, my code had an error: props.each() should be props.each{}

After this within ant.schematool no wonder this worked:

props.each {
        sysproperty(key: it.key, value: it.value)

For the record, it revealed this is not the way to set those properties… The schemaTool ant task has a ‘props’ parameter. Using it this way the task started to work.

Thanks for your comment. Zsolt