2010-04-29 41 views
1

我目前正在使用自動遞增版本號的腳本。該版本的格式爲major.minor.build,因此我無法使用buildnumber。我已經設法增加文件中的屬性,如下所示:Ant更新文件中的版本號但不包含在腳本中

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

這可以工作,但ver.minor不會在腳本中增加。 <property file="build.properties"/>也沒有幫助。

回答

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> 

亞歷山德羅的例子是爲ActionScript它沒有對我的Java工作也很好,所以這裏的我用什麼:

<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 
相關問題