Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute Ant action always and independently from target

Tags:

build

ant

Is there a way to specify actions like <copy> in an Ant buildfile that get executed every time the build file gets read by ant (regardless of the target which is called)?

The background is: I want a *.properties-file to be automatically created from a template when it's not present. I know, I could specify a target which does this and then include it at the root of the dependency-tree but maybe there is a more elegant solution. Because actually the problem is a bit more complex: the ant file where the *.properties-file is read-out is imported by other build files and I don't want to cross-reference targets between them.

I hope I explained my problem sufficiently. In cases of questions do not hestitate to ask.

This is my first posting here. Hope you can help - Greetings from Germany, Ben.

like image 299
Ben Avatar asked Dec 11 '25 06:12

Ben


1 Answers

Just put the code at the top of the file, outside of a target definition.

<project name="myproject" default="mytarget" basedir=".">

  <echo message="Hello there." />

  <target name="mytarget">
    <!-- Do stuff. -->
  </target>

  <target name="myothertarget">
    <!-- Do other stuff. -->
  </target>

</project>

In this case the echo will get executed once before any target, regardless of which target is invoked.

like image 158
Dan Dyer Avatar answered Dec 12 '25 20:12

Dan Dyer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!