Find hidden dependencies in Ivy
Asked Answered
K

2

10

I'm using Apache Ivy + IvyDE for getting my project's dependencies, which are:

    <dependency org="com.google.guava" name="guava" rev="r08" />

    <!-- logging -->
    <dependency org="org.slf4j" name="jcl-over-slf4j" rev="1.6.1" />
    <dependency org="ch.qos.logback" name="logback-classic" rev="0.9.27" />

    <!-- database -->
    <dependency org="org.hibernate" name="hibernate-entitymanager" rev="3.6.2.Final" />
    <dependency org="org.hibernate" name="hibernate-validator" rev="4.1.0.Final" />
    <dependency org="org.hibernate" name="hibernate-c3p0" rev="3.6.2.Final" />
    <dependency org="mysql" name="mysql-connector-java" rev="5.1.14" />

Sources are the Maven and JBoss (Hibernate) repositories.

As you can see I'm using logback+SLF4J for logging, but for some reason Ivy will download log4j and slf4j-log4j as well, which causes a few small problem in my application.

Is there a way to see why this happens, to see which of the dependencies above depend on log4j? Can I get a dependency graph/tree generated from Ivy/IvyDE?

And is there then a way to prevent this from happening?

Kathie answered 23/3, 2011 at 12:35 Comment(0)
R
20

We have an ant target that looks like this:

<target name="report" depends="init">
    <mkdir dir="report" />
    <!-- 
     The type attribute is optional, we're using it to exlude other dependcy types we're not interested in. 
     Note that each resolve uses that list (via a property) in our build. 
    -->
    <ivy:resolve type="jar,ejb,tld,bundle"/> 
    <ivy:report todir="report" />
</target>

Then it's just a call ant report and Ivy will generate the report as HTML in the given directory.

Take a look at the Ivy documentation for ivy:report.

Edit:

To prevent the inclusion of those artifacts/dependencies, you could try transitive="false" on the <dependency ..> element, or use <exclude>. For example, we use Hibernate 3 but don't want to have JTA 1.1, so our ivy.xml containts this: <exclude module="jta"/> to exclude all transitive JTA dependencies.

Rosalba answered 23/3, 2011 at 12:42 Comment(8)
Works perfectly, report to find the culprit (hibernate-validator), exclude to cut log4j outKathie
No wait, I still get log4j when building with Ant, or running from Eclipse, even though it doesn't show up in the ivy.xml [*] listing in Eclipse.Kathie
Well, there might be another dependency that has log4j as a transitive dep. Did you globally exclude log4j, not just for hibernate-validator?Rosalba
I didn't exclude it globally, but according to the report only hibernate-validator depends on it.Kathie
Never mind, it was because log4j was in an included Eclipse projectKathie
Where does this code snippet go? I tried putting it in build.xml and got errors regarding the ivy prefix in ivy:resolve.Catamenia
@AnnKilzer yes, this snippet has to be added to build.xml. Of course you'd also have to add the ivy plugin/taskdefs as well.Rosalba
@AlekseiEgorov it's a property that contains a comma separated list of types, e.g. jar,ejb,tld,bundle. I'll adapt the answer.Rosalba
A
4

I'd like to build on Thomas' answer and recommend adding a "conf" declaration to the dependencies:

    <dependency org="org.slf4j" name="jcl-over-slf4j" rev="1.6.1" conf="default"/>
    <dependency org="ch.qos.logback" name="logback-classic" rev="0.9.27" conf="default"/>

This will reduce the transitive dependencies to the default sub-set, which in Maven terminology is the jars on the "compile" scope.

Without this setting you get all the dependencies which includes lot of optional stuff you won't need.

Anything answered 23/3, 2011 at 18:32 Comment(4)
@mark : I tried following but its not working : <dependency org="log4j" name="log4j" rev="1.2.17" conf="default"/> any help?Unimposing
@tejas you need to supply more details about what's going wrong. My first guess is perhaps you are behind a network proxy? I suggest post a new question.Tanhya
@tejas Ahhh, then I'm guessing you've created your own configurations and "default" is not present. Cannot confirm without more information.Tanhya
Oh ! now I get it. Yes you are right I did create compile,runtime,runtime-test configurations. I didn't know default comes from there. I was assuming its something that is supported irrespective. Thanks for help.Unimposing

© 2022 - 2024 — McMap. All rights reserved.