如何在ant

时间:2017-08-09 14:56:33

标签: ant

enter code here我想从ant build.xml中的属性文件中增加我的版本 我正在使用下面的代码。 它能够增加版本,但同时它是四舍五入的。 4.1.0正在变成5.我的属性文件:

buildversion = 4.1.0

我的代码:            

  <target name="info">
  <echo>Hello World - Welcome to Apache Ant!</echo>
  <propertyfile file="build.properties">

  <entry key="buildversion" type="int" operation="+" value="1"/>
  </propertyfile>
  </target>

  </project>

我读了关于propertyfile的内容,它只支持int,date和string。 我怎么能这样做?

1 个答案:

答案 0 :(得分:1)

major添加了字段。minorrelease - buildtimestamp

<target name="info">
  <echo>Hello World - Welcome to Apache Ant!</echo>

  <!-- Declare, set and increment the values -->
  <propertyfile file="build.properties">
    <entry key="buildmajor" type="int" default="0"/>
    <entry key="buildminor" type="int" default="0"/>
    <entry key="buildrelease" type="int" default="0"/>
    <entry key="buildbuild" type="int" default="0" operation="+" value="1"/>
    <!-- ISO timestamp -->
    <entry key="buildtime" type="date" value="now" pattern="yyyy.MM.dd HH:mm:ss"/>
  </propertyfile>

  <!-- Re-read values -->
  <property file="build.properties"/>

  <!-- Set calculated value based on re-read values -->
  <propertyfile file="build.properties">
    <entry key="buildversion"
           value="${buildmajor}.${buildminor}.${buildrelease}-${buildbuild}"/>
  </propertyfile>
</target>

编辑上述代码段以在计算版本字符串之前重新读取更改的值。

还添加了一些评论......

相关问题