How to set system properties for an ant task

Hello,

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.

Thanks!

task schemaTool << {
    def props = new Properties();
    File f = new File(sourceSets.main.output.resourcesDir, "pg-nucleus.properties")
    f.withInputStream { props.load(it) }
    println "Loaded " + props.size() + " local properties"
      ant.taskdef(name: 'schematool',
            classname: 'org.datanucleus.store.schema.SchemaToolTask',
            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')
        }
          props.each(
            ant.properties[it.key] = it.value
        )
    }
}

The original task (excerpt):

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

you’re setting ant.properties 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