java 在 Ivy 中查找隐藏的依赖项

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5405310/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 10:58:36  来源:igfitidea点击:

Find hidden dependencies in Ivy

javalog4jivydependency-management

提问by Bart van Heukelom

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? Can I get a dependency graph/tree generated from Ivy/IvyDE?

有没有办法看看为什么会发生这种情况,看看上面的哪些依赖项依赖于 log4j?我可以获得从 Ivy/IvyDE 生成的依赖图/树吗?

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

那么有没有办法防止这种情况发生?

回答by Thomas

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 reportand 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.

查看ivy:report 的 Ivy 文档

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.xmlcontaints this: <exclude module="jta"/>to exclude all transitive JTA dependencies.

为了防止包含这些工件/依赖项,您可以尝试transitive="false"使用该<dependency ..>元素,或使用<exclude>. 例如,我们使用 Hibernate 3 但不想有JTA 1.1,所以我们包含ivy.xml<exclude module="jta"/>排除所有可传递的 JTA 依赖项。

回答by Mark O'Connor

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.

如果没有此设置,您将获得所有依赖项,其中包括许多您不需要的可选内容。