Question

I have a build.xml file in my ant project and I'm trying to set a build number with properties. I have the following fields in a file called version.properties:

build.major.number
build.minor.number
build.revision.number
build.number

and my build.number format is:

${build.major.number}.${build.minor.number}.${build.revision.number}

and I am currently updating the number of the revision with propertyfile operation="+" when running my "dist" target. Now everything is working quite fine, except that the build number is always taken from the previous build eg revision.number = 5, build number = 1.1.4.

I have gotten it to work with making 2 targets and dependency for updating the version.properties file with firstly updating the revision number and then in the next target updating the build.number file.

It seems that the operation="+" is executed after every value assignment in a target so I can get the updated value with creating a new target, but it seems sloppy and I would like to be able to do it in only 1 target.

If the 2-target option is as clean as you can get without any JS scripts or any extra packages then okay, I just need to know if it is like that.

Was it helpful?

Solution

Original version.properties

build.major.number=1
build.minor.number=1
build.revision.number=4
build.number=1.1.4

build.xml

<project name="ant-propertyfile-task" default="run" basedir=".">
    <target name="run">
        <propertyfile file="version.properties">
            <entry key="build.revision.number" type="int" operation="+" value="1"/>
        </propertyfile>

        <loadproperties srcFile="version.properties"/>

        <property 
            name="new.build.number" 
            value="${build.major.number}.${build.minor.number}.${build.revision.number}"
        />

        <propertyfile file="version.properties">
            <entry key="build.number" value="${new.build.number}"/>
        </propertyfile>
    </target>
</project>

Updated version.properties

build.major.number=1
build.minor.number=1
build.revision.number=5
build.number=1.1.5
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top