如果选择了编译或 dist 目标,则此解决方案会自动递增次要或修订版号。如果已设置以下属性之一,则可以关闭增量:
- -Dno.increment.minor=true
- -Dno.increment.revision=true
如果已设置属性 inc.major,则主数将递增,其他两个值都将设置为零。SHA-1 校验和由版本文件的文本表示形式计算。
顺便说一句:如果允许,您可以在java脚本中创建自己的ant任务,该脚本包含在JDK 6中。
现在是蚂蚁文件
<?xml version="1.0" encoding="UTF-8"?>
<project name="Numbers" default="dist" basedir=".">
<property name="version.file" location="${basedir}/version.properties"/>
<target name="inc.revision.properties" unless="no.increment.revision">
<propertyfile file="${version.file}">
<entry key="minor.number" default="00" operation="=" pattern="00" type="int"/>
<entry key="major.number" default="00" operation="=" pattern="00" type="int"/>
<entry key="build.number" default="00" operation="+" pattern="00" type="int"/>
</propertyfile>
</target>
<target name="inc.minor.properties" unless="no.increment.minor">
<propertyfile file="${version.file}">
<entry key="minor.number" default="00" operation="+" pattern="00" type="int"/>
<entry key="major.number" default="00" operation="=" pattern="00" type="int"/>
<entry key="build.number" value="00" operation="=" type="int"/>
</propertyfile>
</target>
<target name="inc.major" if="inc.major">
<property name="no.increment.minor" value="true" />
<property name="no.increment.revision" value="true" />
<propertyfile file="${version.file}">
<entry key="minor.number" value="00" operation="=" pattern="00" type="int"/>
<entry key="major.number" default="00" operation="+" pattern="00" type="int"/>
<entry key="build.number" value="00" operation="=" pattern="00" type="int"/>
</propertyfile>
<load.version.info/>
</target>
<target name="inc.minor" depends="inc.major,inc.minor.properties">
<property name="no.increment.revision" value="true"/>
<load.version.info/>
</target>
<target name="inc.revision" depends="inc.major,inc.revision.properties">
<load.version.info/>
</target>
<macrodef name="load.version.info">
<sequential>
<property file="${version.file}"/>
<checksum file="${version.file}" property="sha1.number" algorithm="SHA" format="CHECKSUM"/>
<echo>Version: ${major.number}.${minor.number}.${build.number}</echo>
<echo>SHA1: ${sha1.number}</echo>
</sequential>
</macrodef>
<target name="compile" depends="inc.revision" description="Compile Task"/>
<target name="dist" depends="inc.minor, compile" description="Dest Task"/>
</project>