Max Did It
Coding
,Fri
Post the First Comment
Tagged ,

Inheriting From Ivy XML Files

I have now talked about how you can publish artifacts to your local repository and how Ivy resolves dependencies for your project.

As mentioned, Ivy uses the ivy.xml to know what files and libraries your project depends on. Ivy tries to retrieve these and will copy them into your project folder.

In another post, I have described how I keep my Ant build.xml files small and clean by putting targets I use often into central files. But not only build.xml files can contain information you need time and time again. Certain dependencies or Ivy settings might be used in many projects, and I don’t want to copy them around, either.

Matryoshka Dolls

© 2012 Max Knoblich


Maven has parent POM files, which are pom.xml files you can inherit from. All settings, dependencies, plugins etc. from the parent POM are used and can be extended or overwritten. With this, you can create a hierarchy of build files that you can combine as needed.

Ivy has a similar mechanism, though it is not as refined as Maven’s. Still, you can use it to put often used dependencies in “parent Ivy XMLs”.

Extending Other ivx.xml Files

An ivy.xml should always contain the info tag with the organisation, module and revision properties in it.

1
2
3
4
5
6
7
<?xml version="1.0" encoding="utf-8"?>
<ivy-module version="2.0">
	<info organisation="de.maxdidit"
		  module="${artifact-name}"
		  revision="${version}">
	</info>
</ivy-module>

The info tag can contain several other tags. One of them is the extends tag with which you can extend other ivy.xml files.

These information of the XML can be used by the inheriting file:

  • The information contained in the info tag.
  • The description.
  • The configutations.
  • The dependencies.
  • The licenses specified in the parent file.

By default, all of the mentioned aspects are used by the ivy.xml using extends. By the way, take note that dependencies of the parent file will be inherited, but not any exclude tags.

1
2
3
4
5
6
7
8
9
10
11
<?xml version="1.0" encoding="utf-8"?>
<ivy-module version="2.0">
	<info organisation="de.maxdidit"
		  module="${artifact-name}"
		  revision="${version}">
		<extends extendType="all"
				 organisation="de.maxdidit"
				 module="parent-ivy-swf"
				 revision="1.0.0" />
	</info>
</ivy-module>

With the above modification to the ivy.xml, your project will now receive all dependencies declared in the parent-ivy-swf module.

This configuration does assume that the ivy.xml you want to extend is located in the repository. If you don't want to publish the parent Ivy file everytime you modify it, you can also reference it directly in your local file system. This is done with the location property.

1
2
3
4
5
6
7
8
9
10
11
12
<?xml version="1.0" encoding="utf-8"?>
<ivy-module version="2.0">
	<info organisation="de.maxdidit"
		  module="${artifact-name}"
		  revision="${version}">
		<extends extendType="all"
				 organisation="de.maxdidit"
				 module="parent-ivy-swf"
				 revision="1.0.0"
				 location="../../../Commons/Ivy/parent-ivy-swf.xml" />
	</info>
</ivy-module>

I, for example, declare libraries for unit tests and mock objects in a parent Ivy XML. This saves me the annoying copy-paste rituals at the start of a project and keeps my project's ivy.xml smaller and cleaner.

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>