Ant更新文件中的版本号,但不在脚本中

时间:2010-04-29 08:26:13

标签: ant

我目前正在开发一个自动增加版本号的脚本。该版本采用major.minor.build格式,因此我无法使用buildnumber。我已设法在文件中增加属性,如下所示:

<propertyfile file="./build.properties">
  <entry key="ver.minor" type="int" operation="+" value="1" pattern="0"/>
</propertyfile>

这样可行,但ver.minor不会在脚本中递增。 <property file="build.properties"/>也无济于事。

1 个答案:

答案 0 :(得分:1)

你可以在亚历山德罗的博客上找到答案/解释:http://www.sephiroth.it/weblog/archives/2010/01/update_your_app_version_using_ant_bui.php 这是目标:

<target name="update-version">
<propertyset id="tdate"></propertyset>
<tstamp>
    <format property="tdate" pattern="yyyyMMdd"/>
</tstamp>
<buildnumber file="build.number"/>
<echo>updating version to current datetime: ${tdate}</echo>
<replaceregexp byline="true">
    <regexp pattern="public static const BUILD_DATE: String = \'([0-9]+)'"/>
    <substitution expression="public static const BUILD_DATE: String = '${tdate}'"/>
    <fileset dir="src/it/sephiroth/somestuff">
        <include name="Library.as"/>
    </fileset>
</replaceregexp>

<replaceregexp byline="true">
    <regexp pattern="public static const BUILD_NUMBER: String = \'([0-9\.]+)'"/>
    <substitution expression="public static const BUILD_NUMBER: String = '${build.number}'"/>
    <fileset dir="src/it/sephiroth/somestuff">
        <include name="Library.as"/>
    </fileset>
</replaceregexp>

Alessandro的例子是针对我在Java上运行得不好的Actionscript,所以这就是我使用的:

    <target name="update-version">
    <property file="build_info.properties" />
    <property name="build.number" value="${build.major.number}.${build.minor.number}.${build.revision.number}" />
    <echo>Updating build number: ${build.number}</echo>
    <propertyset id="tdate" />
    <tstamp>
        <!-- 02.10.2011 21:27 -->
        <format property="tdate" pattern="MM.dd.yyyy hh:mm" />
    </tstamp>
    <echo>Updating version to current datetime: ${tdate}</echo>
    <replaceregexp byline="true"
        match="BUILD_DATE = &quot;([0-9\.]+)&quot;" 
        replace="BUILD_DATE = &quot;${tdate}&quot;">
        <fileset dir="src/my/package">
            <include name="Application.java" />
        </fileset>
    </replaceregexp>
    <replaceregexp byline="true"
        match="BUILD_NUMBER = &quot;([0-9\.]+)&quot;" 
        replace="BUILD_NUMBER = &quot;${build.number}&quot;">
        <fileset dir="src/my/package">
            <include name="Application.java" />
        </fileset>
    </replaceregexp>
</target>

唯一的问题是你必须有一个名为“build_info.properties”的属性文件,其中包含三个属性。

build.major.number=01
build.minor.number=00
build.revision.number=0001