ant Getting started with ant Print environment information before build

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

The following is handy to have in build logs that identifies the build machine, and some parameters; simply make you main task depend on this task to print it before every build.

<!-- 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>

This will result in the following output,

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


Got any ant Question?