venerdì 13 aprile 2012

Ant Tips


1- Launching  Multiple Ant build
Commonly a complete software delivery is made of a set of jar/war files and each jar/war file may be produced by a distintinct ant .xml build file.
To make full release you wish to launch a building process that will call each  ant file in sequence.
This is a sample of a possible solution:
Assume that the whole software realease is the union of this 2 projects (named Project1 and Project2).
Assume that  and each project has it own directory structure and its own build.xml and build.properties file so directory structure is :
/root
     -> Project1
      ->Project2

You may define an upper level  ant file in the root directory:
 <target name="softwareRelease"  description="my full build ant task">
  <ant antfile="Project1/build.xml" target="Build_And__deploy_Jar" inheritAll="false">
   <property file="Project1/build.properties"/>
  </ant>
  <ant antfile="Project2/build.xml" target="Build_And__deploy_Jar" inheritAll="false">
   <property file="Project2/build.properties"/>
  </ant>
 </target>

inheritAll="false" means that each ant refers only to its build.properties file.


2- Ant parameters
Basically you have tree choices to pass parameters to ant build file

build.properties file
This is most used option. Good if your property are the same in all build environment (developers pc , code management environment) otherwise choose another option.
es: in build.properties  file define client.jar.name=file.jar
To use property defined in build.properties file put in build.xml file
<project name="myproject" basedir="." default="build">
 <property file="build.properties"/>
.........
${client.jar.name}


environment variables
This options loads all environment properties. This is a more flexible option than the previous one so you may define different variable values in different building environments.
To use env vars in ant build.xml file
<project name="myproject" basedir="." default="build">
<property environment="env"/>
 ......
env.property

-Dproperty_name=property_value
Also a good option. You may launch ant build with a -Dproperty_name=property_value (as many as you need). This way you may override property value defined in build.properties file (good to ovverride development property values with code management environment values).

Nessun commento:

Posta un commento