Question

I have 2 vars that I need. first is DSTAMP with yyyy-MM-dd formatting and the other one is the buildNumber from my .build file. In a simple structure like this :

<project .....>

   <property ....>

   <target ....>

   <target .....>

</project>

My question is, how can I set the ${build.number} and DSTAMP like a property? I've tried to do this :

<project .....>

   <tstamp>
   <format property="DSTAMP" pattern="yyyy-MM-dd" />
</tstamp>

   <buildnumber file=".build"/>

   <property ....>

   <target ....>

   <target .....>

</project>

I thought i could then access it with ${build.number} and ${DSTAMP} anywhere in my ant script but it says unexpected token. How can i store these properties to access them anywhere?

Ant version 1.5.4. It seems to accept it in Ant 1.6+ but I would rather not change my library just for this.

Was it helpful?

Solution

Ok I used another solution as buildNumber task doesn't behave like I want :

<project name="MyProject" default="all" basedir=".">

 <taskdef resource="net/sf/antcontrib/antlib.xml"/>

 <tstamp>
    <format property="DSTAMP" pattern="yyyy-MM-dd" />
    <format property="TODAY" pattern="yyyy-MM-dd HH:MM:SS" />
 </tstamp>
 <property file=".build"/>
 <property name="buildNum" value="${build.number}"/>

 [... some tasks ...]

 <target name="incrementVersion">
        <echo>Building version ${build.number} success</echo>
        <propertyfile file="./.build" comment="Build Number">
                <entry key="build.number" type="int" operation="+" default="1000" pattern="0000"/>
        </propertyfile>
 </target>

<target name="all" depends="some,other,target,incrementVersion"/>
</project>

This way I'm 100% certain that it will only increment at the end of my tasks and only if it succeed. Only minor problem here, you have to run incrementVersion once so it can initialize the buildNumber parameter. I could do some if exist control but since my file will never be deleted I don't care. You have to use Ant 1.6+ and Ant Contrib. I use Ant 1.8.2 and Ant Contrib 1.0b3 thanks all.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top