Max Did It
Coding
,Sat
1 Comment
Tagged ,

Resolve Dependencies With Ivy

In my last post, I wrote about how you can use Apache Ivy to automatically store your compiled components and libraries in a local repository. Now, why should you even do that? What’s the point?

The point is, that now you can use Ivy to

  • automatically copy the libraries you need into your project’s folder structure,
  • always retrieve the latest version of a library,
  • download libraries from remote repositories, provided you have access and
  • get dependencies that aren’t even in any of your repositories.
Ivy: Work, Work

“Work, Work”. Apache Ivy can take a bunch of manual tasks off your hands. © 2012 Max Knoblich

This is how I use Ivy to make working with libraries easier:

Define And Resolve Dependencies

In my last post, I already mentioned the ivy.xml. This file is usually put in the same folder as Ant’s build.xml and contains information like the name of the project to be built and it’s version number.

This is also where you tell Ivy which libraries your project depends on. Just like the project itself, you have to set the dependencies name, version and organistation name, since this is the format they are stored in the repository. Dependencies are stored in the dependencies tag (surprise!), which is a child element of the ivy-module tag.

16
17
18
19
20
21
<ivy-module version="2.0">
[...]
	<dependencies>
		<dependency org="de.maxdidit" name="linked-list" rev="1.0.0" />
	</dependencies>
</ivy-module>

This enables Ivy to copy the SWC files from your local or remote repository and put them into your project folders. To make Ivy actually do that, you need to go to your project’s build.xml and call the respective Ant tasks.

32
33
34
35
36
<target name="retrieve">
	<!-- Resolve and retrieve dependencies -->
	<ivy:resolve refresh="true" showprogress="true" />
	<ivy:retrieve pattern="${library-path}/[module]-[revision](-[artifact]).[ext]" />
</target>

The resolve tag looks up where the dependencies are and can also resolve dependencies recursively. If a library relies on other files to work properly, Ivy can try to get these files as well.

The retrieve tag then actually copies the files into your project, relying on the pattern you pass to it. This is where you put the folder and the name format you want your libraries to appear in.

Always Use The Latest Version

Another neat feature is that you can tell Ivy not to get a specific version of a SWC, but always the latest one present in the repository. This comes in handy if you or someone else updates a certain library very often. This is simply done by putting the latest.integration keyword into the “rev” property in your ivy.xml file.

16
17
18
19
20
21
<ivy-module version="2.0">
[...]
	<dependencies>
		<dependency org="de.maxdidit" name="linked-list" rev="latest.integration" />
	</dependencies>
</ivy-module>

You can also tell Ivy to use the latest version up until a certain major release. If you want the latest 1.x.x release of a SWC, but can’t use the 2.0.0 release due to too many changes, you can do that to. The syntax for the different cases you can model can be found in the documentation of the dependency tag.

Access Local Files

So, what about libraries that have not been put into your repository? While many third party Java libraries are already available in public remote Maven repositories, Actionscript SWC files are still mostly downloaded from the developers homepage. You can publish them into your repository after downloading them, but I have decided against that step, since it isn’t really necessary.

Ivy makes it relatively easy to access files that are not in any of your repositories. This is simply done by putting an artifact tag into a dependency tag in the ivy.xml. You can put additional information about a dependency into the artifact tag, one of which is where Ivy should download the library if it can’t be found in the repository.

This can point to a local file or a remote URL.

14
15
16
<dependency org="org.mockito" name="mockito" rev="1.4M3">
	<artifact name="" type="swc" ext="swc" url="file:///c:/tools/mockito/mockito-1.4M3.swc" />
</dependency>

After doing this, Ivy will try to resolve and copy the file into your project like any other SWC from your repository.

Next Up: Inheriting From Other Ivy Files

Now, maybe you have certain dependencies that a couple, maybe even most of your projects rely on. You can copy those into each ivy.xml everytime you start a new project. You can also put them into a single XML file once and then inherit from that file each time you need to. I will write about that in the next blog post.

Comments

1 Comment has been posted so far - Leave a Comment

Max
Max
,Fri

Mit ivy hab ich noch nix gemacht, komme aus der Php welt. Klingt aber recht interessant. Hast du dir mal composer angeschaut? Das kommt zwar vom den Entwicklern des symfony frameworks sollte aber sprach unabhängig funktionieren.

Gruß max

Btw.... nette Zeichnung :-)

Reply

Leave A Comment

Your email address will not be published. Required fields are marked *

Connect with Facebook

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>