I am building a project using Ant and Ivy. The build.xml
file depends on ant-contrib, bean scripting framework, beanshell, and commons-logging.
Ant searches for libraries in several places, including ${user.home}/.ant/lib
.
Is there any way in the build.xml
file to have these libraries automatically download and install in the ${user.home}/.ant/lib
directory if they are not already present, perhaps using Ivy itself?
Thanks, Ralph
I happened on this question as I was reading the Ivy cachefileset documentation, which states:
Please prefer the use of retrieve + standard ant path creation, which make your build more independent from ivy (once artifacts are properly retrieved, ivy is not required any more).
The Ivy cachepath documentation similarly states:
If you want to make your build more independent from Ivy, you could consider using the retrieve task. Once the artifacts are properly retrieved, you can use standard Ant path creation which makes Ivy not necessary any more.
So, it would seem a better answer would be to modify Mark's response to something that uses retrieve in conjunction with ant paths. Something along the lines of the following:
<configurations>
<conf name="tasks" description="Ant tasks"/>
</configurations>
<dependencies>
<dependency org="ant-contrib" name="cpptasks" rev="1.0b5"
conf="tasks->default"/>
<dependency org="junit" name="junit" rev="3.8" conf="tasks->default"/>
..
In your build.xml file you can create a path from this config
<ivy:retrieve conf="tasks"
pattern="${dir.where.you.want.taskdef.jars}/[artifact]-[revision].[ext] />
<path id="tasks.path">
<fileset dir="${dir.where.you.want.taskdef.jars}">
<include name="**/*.jar"/>
</fileset>
</path>
<taskdef name="task1" classname="??" classpathref="tasks.path"/>
<taskdef name="task2" classname="??" classpathref="tasks.path"/>
This would even allow you to move the retrieve task into a separate ant file that deals with dependencies. Thereby, you don't have to rely on ivy after your dependencies are retrieved into their directories.
The intention of ivy is that you use it to pull down your jars (resolve & retrieve). Once you have them in place, you can switch back to using standard Ant.
<ivy:retrieve conf="tasks" />
Also Note: visit the 'Path-like Structures' section of this page for more on "standard ant path creation"