在構建之前列印環境資訊
以下內容在構建日誌中具有識別構建機器和一些引數的便利性; 簡單地讓你 main
任務依賴於這個任務在每次構建之前列印它。
<!-- Print Environment Info -->
<target name="environment">
<!-- Get the current timestamp -->
<tstamp>
<format property="TODAY_UK" pattern="yyyy-MM-dd HH:mm:ss:sss zzz" locale="cn,CN" />
</tstamp>
<!-- Get the hostname of the system -->
<exec executable="hostname" outputproperty="os.hostname" />
<!-- Print a bunch of information -->
<echo message="" />
<echo message=" Build Information" />
<echo message="" />
<echo message=" OS Information" />
<echo message="" />
<echo message=" User : ${user.name}" />
<echo message=" Hostname : ${os.hostname}" />
<echo message="" />
<echo message=" Name : ${os.name}" />
<echo message=" Version : ${os.version}" />
<echo message=" Build : ${os.arch}" />
<echo message="" />
<echo message="" />
<echo message=" Java Information" />
<echo message="" />
<echo message=" Version : ${ant.java.version} / ${java.version}" />
<echo message=" Java Home : ${java.home}" />
<echo message="" />
<echo message="" />
<echo message=" Current Time : ${TODAY_UK}" />
<echo message="" />
</target>
這將導致以下輸出,
environment:
[echo]
[echo] Build Information
[echo]
[echo] OS Information
[echo]
[echo] User : <User Name>
[echo] Hostname : <Host Name>
[echo]
[echo] Name : Windows 8.1
[echo] Version : 6.3
[echo] Build : amd64
[echo]
[echo]
[echo] Java Information
[echo]
[echo] Version : 1.8 / 1.8.0_45
[echo] Java Home : C:\Program Files\Java\jdk1.8.0_45\jre
[echo]
[echo]
[echo] Current Time : 2016-04-18 00:40:11:011 EDT