How to omit attributes not defined by user in Ant task execution?

Hi,

I’m working on a Gradle plugin which internally uses already existing Ant task. Some properties are optional in Ant task (the default value is used). I don’t want to define my own default values and use it when not defined by user in build.gradle, but rather use those from Ant by omitting a parameter when calling Ant task.

Example (inside AntBuilder):

ant.someTask(required1: "required1", optional1: "optional1") //in case an optional attribute is defined in a configuration
  ant.someTask(required1: "required1") //in case an optional attribute is not defined

I know how to do it with nested elements, but how to work with tag attributes?

Regards Marcin

Are you saying that simply omitting the optional parameter (as in your second line) doesn’t work?

Thanks for your reply. No, I didn’t describe my problem precisely enough.

The original problem was to pragmatically don’t pass a property to Ant when it is not set in Gradle. Later I realized that it is just a map and can do something like that:

def map = [:]
map[ "required1" ] = getRequired1()
map[ "optional1" ] = getOptional1()
ant.someTask(map.findAll( {it.value != null} )

to filter out a properties with null value and it seems to work fine, but I faced another problem.

Optional property can be set by end-developer in his/her build.gradle, but if not I would like to keep there null value to allow to filter it out later from a map passed to ant. Unfortunately when I pass null value to a property defined in a task as @Input I’ve got “No value has been specified for property ‘optional1’.” error.

Can I define @Input in a task as optional (make a promise to Gradle to take care about potential null values)?

Can I define @Input in a task as optional (make a promise to Gradle to take care about potential null values)?

You can use ‘@Optional’.

Great. I was looking for a “optional” attribute in an annotation and did think about another annotation :).

Thanks for your help.