Find hidden dependencies in Ivy

2019-03-15 14:38发布

问题:

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?

回答1:

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.



回答2:

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.