views:

2698

answers:

4

I can't find any thorough explanation of the ivy dependency tag's conf attribute:

<dependency org="hibernate" name="hibernate" rev="3.1.3" conf="runtime, standalone -> runtime(*)"/>

See that conf attribute? I can't find any explanation (that I can understand) about the right hand side of the -> symbol. PLEASE keep in mind I don't know the first thing about maven so please explain this attribute with that consideration.

Yes, I've already looked at this: http://ant.apache.org/ivy/history/latest-release/ivyfile/dependency.html

Thanks, Dan

+9  A: 

First of all, Ivy is not Maven ;)
Maven2 is a software project management and comprehension tool, whereas Ivy is only a dependency management tool.

Ivy heavily relies on a unique concept called configuration.
In ivy, a module configuration is a way to use or to see the module.
For instance, you can have a test and runtime configuration in your module. But you can also have a mysql and an oracle configuration. Or an hibernate and a jdbc configuration.

In each configuration you can declare:

  • what artifacts (jar, war, ...) are required.
  • your dependencies on other modules, and describe which configuration of the dependency you need. This is called configuration mapping.

So the conf attribute does precisely that: Describes a configuration mapping for a dependency.
The mapped child element is your "right hand side of the -> symbol" and represents the name of the dependency configuration mapped. '*' wildcard can be used to designate all configurations of this module.


Maven2 on its side has something called the scope.
You can declare a dependency as being part of the test scope, or the buildtime scope.
Then depending on this scope you will get the dependency artifact (only one artifact per module in maven2) with its dependencies depending on their scope. Scopes are predefined in maven2 and you can't change that.

That means :

There are a lot of unnecessary dependencies downloaded for many libraries.
For example, Hibernate downloads a bunch of JBoss JARs and the Display Tag downloads all the various web framework JARs. I found myself excluding almost as many dependencies as I added.

The problem is that hibernate can be used with several cache implementations, several connection pool implementation, ... And this can't be managed with scopes, wheres Ivy configurations offers an elegant solution to this kind of problem.
For instance, in ivy, assuming hibernate as an ivy file like this one, then you can declare a dependency like that:

<dependency org="hibernate" name="hibernate" rev="2.1.8" conf="default->proxool,oscache"/>

to get hibernate with its proxool and oscache implementations, and like that:

<dependency org="hibernate" name="hibernate" rev="2.1.8" conf="default->dbcp,swarmcache"/>

to get hibernate with dbcp and swarmcache.

By mapping your default master configuration to "proxool,oscache" or to "dbcp,swarmcache", you specify what you need exactly from the module "hibernate".


You can find those "proxool,..." arguments by listing the ivy configuration defined for each modules associate with the library. For instance:

<ivy-module version="2.0">
<info organisation="ssn-src" module="pc"/>
<configurations defaultconfmapping="default->default">
 <conf name="default" />
 <conf name="provided" description="they are provided by the env." />
 <conf name="compile" extends="default,provided" />
 <conf name="war" extends="default"/>
</configurations>
<dependencies>

Example:

let's suppose modA has two configurations, default and test.
As a practical matter, it's going to be highly unusual to want to leave out the conf attribute of the dependency element.
The ivy.xml for modA might have a dependency:

<dependency org="theteam" name="modB" rev="1.0" conf="default->*" />

You're starting from default, rather than from both default and test.

The above example makes modA's default depend on modB's conf1, conf2, and conf3.
Or you might want to say that modA's default only depends on modB's conf1:

<dependency org="theteam" name="modB" rev="1.0" conf="default->*conf1*" />
VonC
Ok, I think I almost get it. But where do you find your options? How did you know you can say proxool,oscache/dbcp,swarmcache?
tieTYT
That "unnecessary dependencies downloaded" IS addressable in Maven, via excluding default transitive dependencies and making your choices explicit. But I will be the first to admit that it is by no means "elegant".
mezmo
+4  A: 

Thanks VonC!

It helped me alot further.

When it comes to options (configurations) tieTYT, you can find them in the ivy-[revision number].xml file in your Ivy repository under: organization name --> module name.

An example configurations element from the JUnit 4.6 revision downloaded from http://www.springsource.com/repository/app/.

<configurations>
 <conf name="compile" visibility="public" description="Compile dependencies"/>
 <conf name="optional" visibility="public" extends="compile" description="Optional dependencies"/>
 <conf name="provided" visibility="public" description="Provided dependencies"/>
 <conf name="runtime" visibility="public" extends="compile" description="Runtime dependencies"/>
</configurations>

In my project's ivy.xml file, I have a configuration compile-test. In the dependencies element I have the following dependency:

<dependency org="org.junit" name="com.springsource.org.junit"
  rev="4.6.0" conf="compile-test->compile" />

As you can see, my compile-test configuration depends on the compile configuration in the JUnit's ivy.xml file.

Espen
Completely missed your answer there. Good illustration. +1
VonC
A: 

Aha - I find that very interesting: confs map not only to maven scopes but also to dependency artifactIds. Very helpful!

DrUseful
A: 

It helped me once to understand things this way:

  1. An ivy configuration is simply a name for some subset of the module's artifacts.
  2. Dependencies between modules are specified in terms of configuration names.
Archie