简体   繁体   English

在常春藤中找到隐藏的依赖项

[英]Find hidden dependencies in Ivy

I'm using Apache Ivy + IvyDE for getting my project's dependencies, which are: 我正在使用Apache Ivy + IvyDE获取项目的依赖项,它们是:

    <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. 源代码是Maven和JBoss(Hibernate)存储库。

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. 正如您所看到的,我正在使用logback + SLF4J进行日志记录,但出于某种原因,Ivy也会下载log4j和slf4j-log4j,这会在我的应用程序中引起一些小问题。

Is there a way to see why this happens, to see which of the dependencies above depend on log4j? 有没有办法看到为什么会发生这种情况,看看上面哪个依赖项依赖于log4j? Can I get a dependency graph/tree generated from Ivy/IvyDE? 我可以从Ivy / IvyDE生成依赖图/树吗?

And is there then a way to prevent this from happening? 那么有没有办法防止这种情况发生?

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. 然后它只是一个调用ant report ,Ivy将在给定目录中生成HTML报告。

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> . 要防止包含这些工件/依赖项,可以在<dependency ..>元素上尝试transitive="false" ,或使用<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. 例如,我们使用Hibernate 3但不想拥有JTA 1.1 ,所以我们的ivy.xml这个: <exclude module="jta"/>以排除所有传递JTA依赖项。

I'd like to build on Thomas' answer and recommend adding a "conf" declaration to the dependencies: 我想以Thomas的回答为基础,并建议在依赖项中添加“conf”声明:

    <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. 这将减少对默认子集的传递依赖性,默认子集在Maven术语中是“编译”范围的jar。

Without this setting you get all the dependencies which includes lot of optional stuff you won't need. 如果没有此设置,您将获得所有依赖项,其中包含许多您不需要的可选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM