Dependencies management.
SourceLabs host 'profiles' of mutually compatible versions of Java libraries and maintains Maven(1) compatible repository of libraries. This is very convenient way to track and update 3rd party libraries in Ant projects. In order to do it we just need to put dependencies jar ( part of httpunit project)into ${ANT_HOME}/lib directory and start using it as following:
3 <target name="init">
4 <property name="profile" value="contemporary"/>
5 <property name="release" value="dev"/>
6 <property file="${release}.properties"/>
7 <property file="default.properties"/>
10 <property url="http://fred.sourcelabs.com/maven/${profile}.properties"/>
14 <echo message="OS::${os.name}/${os.arch}"/>
15 <echo message="profile=${profile}"/>
16 <taskdef classname="org.apache.tools.ant.taskdefs.optional.dependencies.Dependencies" name="dependencies"/>
17
18 <dependencies pathId="build.classpath" repositoryList="${repositoryList}">
19 <dependency group="postgresql" version="${postgresql}" />
20 <dependency group="j2ee" version="${j2ee}" />
21 </dependencies>
22
23
24 <dependencies pathId="base.classpath" fileSetId="base.classpath.files" repositoryList="${repositoryList}">
25 <dependency group="activation" version="${activation}" />
26 <dependency group="antlr" version="${antlr}" />
27 <dependency group="asm" version="${asm}" />
28 <dependency group="bsf" version="${bsf}" />
29 <dependency group="cglib" version="${cglib}" />
30 <dependency group="commons-beanutils" version="${commons-beanutils}"/>
31 <dependency group="commons-collections" version="${commons-collections}"/>
32 <dependency group="commons-codec" version="${commons-codec}"/>
33 <dependency group="commons-dbcp" version="${commons-dbcp}"/>
34 <dependency group="commons-digester" version="${commons-digester}"/>
35 <dependency group="commons-fileupload" version="${commons-fileupload}"/>
36 <dependency group="commons-httpclient" version="${commons-httpclient}" />
37 <dependency group="commons-io" version="${commons-io}"/>
38 <dependency group="commons-lang" version="${commons-lang}"/>
39 <dependency group="commons-logging" version="${commons-logging}"/>
40 <dependency group="commons-pool" version="${commons-pool}"/>
41 <dependency group="dom4j" version="${dom4j}"/>
42 <dependency group="hibernate" version="${hibernate}"/>
43 <dependency group="ehcache" version="${ehcache}"/>
44 <dependency group="javassist" version="${javassist}" />
45 <dependency group="junit" version="${junit}" />
46 <dependency group="jython" version="${jython}" />
47 <dependency group="log4j" version="${log4j}" />
48
49 <dependency group="oro" version="${oro}" />
50 <dependency group="ognl" version="${ognl}" />
51 <dependency group="regexp" version="${jakarta-regexp}"/>
52 <dependency group="spring" version="${spring}"/>
53 </dependencies>
54
66
67 </target>
68
Then we can use the files from the declared dependency set(s) like this:
63 <copy todir="${basedir}/build/lib" flatten="true">
64 <fileset refid="base.classpath.files" />
65 </copy>
Or reference them in the compile task:
122 <target name="compile" depends="init">
123 <mkdir dir="build/classes"/>
124 <javac classpathref="base.classpath"
125 destdir="build/classes"
126 srcdir="java">
127 <classpath>
128 <fileset dir="build/lib" includes="*.jar"/>
129 <path refid="build.classpath" />
130 </classpath>
131 </javac>
139 </target>
140
141
As we all know the dependencies management is not that convenient in Java as we would like it to be.
Maven claims to be savor, but not all developers like Maven as build tool. Dependencies task for Ant allows us to leverage useful Maven ideas and infrastructure in Ant based builds.
Another trick to explore is the idea of "profile": "Profile" is a simple properties file that lists all the mutually compatible libraries and their versions.
This is quite convenient because when updates of bugfixes for a certain library becomes available, we simply changes profile definition and dependency task magic brings the necessary update to the build process or runtime.
Note: this strategy is not perfect, but works quite well. One cool feature is that we can switch profiles on the fly, for example we could build our project with our default profile and then just for testing we can try specifying different profiles and see if it breaks anything. Such feature is very useful for testing a migration path.
Feel free to use our profile definition and provide us feedback: something is missing in the profiles or you think that there is a need for another profile. |