1

I have a build process in Java where I need to use the Ant exec task to launch an external program. That external program will then create some sources based on an abstract specification, i.e. a kind of code generation.

How can I get the exec task to execute only if the input to the code generation is newer than the output? I.e. when the input has been modified after the output was last created?

Flow
  • 23,572
  • 15
  • 99
  • 156
Marcus Junius Brutus
  • 26,087
  • 41
  • 189
  • 331

2 Answers2

2

Use the Uptodate task to set a property and add an if or unless with that property to the target which contains your exec task.

joescii
  • 6,495
  • 1
  • 27
  • 32
  • 1
    this is the good advice. However don't use the ant-contrib if, go with unless on the target as @barnesjd ponits out. If you're on 1.9 you can use the native if http://ant.apache.org/manual/ifunless.html – thekbb Sep 25 '13 at 16:36
  • +1 on the ant-contrib comment from @thekbb. It can be handy. However, any time I use it, I feel I'm getting away from the spirit/philosophy of Ant (like it or not) and I find myself fighting Ant rather than working with it. – joescii Sep 25 '13 at 20:00
1

Since I wanted to specify an arbitrary set of target files (which is cumbersome or impossible with Uptodate that only uses the Ant mapper element for multiple target files), I ended up using the ant-contrib OutOfDate task which supported what I wanted more intuitively.

Marcus Junius Brutus
  • 26,087
  • 41
  • 189
  • 331
  • Very cool. I had not seen that one in ant-contrib yet. I'll have to try it next time I have a similar problem. That sounds like one of the features that would be handy but not necessarily fighting against Ant. – joescii Sep 25 '13 at 20:01