如何修复 Apache Ivy 中的逐出模块问题

How to fix Evicted Modules issue in Apache Ivy

我正在尝试将 Apache Ivy 与现有的 Java 使用 Apache Ant 的 EE 项目集成。我创建了 ivy.xml、ivysettings.xml(在 mvnrepo 中添加了一个不存在的 repo)并对现有的 build.xml 进行了更改。

我在 运行 Ivy Resolve 时得到以下结果:

[ivy:resolve] :: resolution report :: resolve 2642ms :: artifacts dl 49ms
[ivy:resolve]   :: evicted modules:
[ivy:resolve]   xml-apis#xml-apis;1.0.b2 by [xml-apis#xml-apis;1.3.04] in [default]
[ivy:resolve]   commons-logging#commons-logging;1.1.1 by [commons-logging#commons-logging;1.2] in [default]
[ivy:resolve]   commons-codec#commons-codec;1.6 by [commons-codec#commons-codec;1.8] in [default]
[ivy:resolve]   commons-logging#commons-logging;1.1.3 by [commons-logging#commons-logging;1.2] in [default]
[ivy:resolve]   org.slf4j#slf4j-api;1.6.1 by [org.slf4j#slf4j-api;1.7.7] in [default]
[ivy:resolve]   xml-apis#xml-apis;1.3.04 by [xml-apis#xml-apis;1.4.01] in [default]
    ---------------------------------------------------------------------
    |                  |            modules            ||   artifacts   |
    |       conf       | number| search|dwnlded|evicted|| number|dwnlded|
    ---------------------------------------------------------------------
    |      default     |  108  |   0   |   0   |   6   ||  102  |   0   |
    ---------------------------------------------------------------------

我该如何解决这个问题? ivy.xml 中没有直接提到这些模块。这是我第一次使用 Ivy 进行实验,如有任何帮助,我们将不胜感激。

ivysettings.xml

<ivysettings>
    <settings defaultResolver="central"/>
    <resolvers>
        <ibiblio name="central" m2compatible="true"/>
        <ibiblio name="primefaces-themes-old" m2compatible="true" root="http://repository.primefaces.org"/>
    </resolvers>
    <modules>
        <module organisation="org.primefaces.themes" resolver="primefaces-themes-old"/>
    </modules>
</ivysettings>

ivy.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<ivy-module version="2.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
    <info organisation="Fetching Life" module="WebApp" status="integration">
    </info>
    <dependencies>
        <dependency org="commons-collections" name="commons-collections" rev="3.2.2" conf="default"/>
        <dependency org="mysql" name="mysql-connector-java" rev="5.1.40" conf="default"/>
        <dependency org="com.googlecode.flyway" name="flyway-core" rev="2.3.1" conf="default"/>
        <dependency org="com.googlecode.flyway" name="flyway-ant" rev="2.3.1" conf="default"/>
        <dependency org="org.hibernate" name="hibernate-core" rev="5.0.11.Final" conf="default"/>
        <dependency org="org.springframework" name="spring-core" rev="4.2.8.RELEASE" conf="default"/>
        <dependency org="org.springframework" name="spring-web" rev="4.2.8.RELEASE" conf="default"/>
        <dependency org="org.springframework" name="spring-orm" rev="4.2.8.RELEASE" conf="default"/>
        <dependency org="org.springframework" name="spring-context" rev="4.2.8.RELEASE" conf="default"/>
        <dependency org="org.springframework" name="spring-context-support" rev="4.2.8.RELEASE" conf="default"/>
        <dependency org="org.springframework" name="spring-test" rev="4.2.8.RELEASE" conf="default"/>
        <dependency org="org.springframework" name="spring-oxm" rev="4.2.8.RELEASE" conf="default"/>
        <dependency org="org.springframework" name="spring-webmvc" rev="4.2.8.RELEASE" conf="default"/>
        <dependency org="org.springframework" name="spring-webmvc-portlet" rev="4.2.8.RELEASE" conf="default"/>
        <dependency org="org.springframework" name="spring-aspects" rev="4.2.8.RELEASE" conf="default"/>
        <dependency org="org.primefaces" name="primefaces" rev="5.1" conf="default"/>
        <dependency org="com.sun.faces" name="jsf-api" rev="2.1.29" conf="default"/>
        <dependency org="com.sun.faces" name="jsf-impl" rev="2.1.29" conf="default"/>
        <dependency org="joda-time" name="joda-time" rev="2.8.2" conf="default"/>
        <dependency org="org.apache.shiro" name="shiro-all" rev="1.2.6" conf="default"/>
        <dependency org="com.google.apis" name="google-api-services-calendar" rev="v3-rev179-1.19.1" conf="default"/>
        <dependency org="com.google.code.gson" name="gson" rev="2.3.1" conf="default"/>
        <dependency org="org.mnode.ical4j" name="ical4j" rev="1.0.7" conf="default"/>
        <dependency org="net.sourceforge.jexcelapi" name="jxl" rev="2.6.12" conf="default"/>
        <dependency org="javax.el" name="javax.el-api" rev="2.2.5" conf="default"/>
        <dependency org="com.ocpsoft" name="prettyfaces-jsf2" rev="3.3.3" conf="default"/>
        <dependency org="org.mindrot" name="jbcrypt" rev="0.3m" conf="default"/>
        <dependency org="javax.jdo" name="jdo-api" rev="3.0.1" conf="default"/>
        <dependency org="org.quartz-scheduler" name="quartz" rev="2.2.3" conf="default"/>
        <dependency org="org.omnifaces" name="omnifaces" rev="1.6.3" conf="default"/>
        <dependency org="javax.servlet.jsp.jstl" name="jstl-api" rev="1.2" conf="default"/>
        <dependency org="antlr" name="antlr" rev="2.7.7" conf="default"/>
        <dependency org="org.apache.james" name="apache-mime4j" rev="0.6.1" conf="default"/>
        <dependency org="org.atmosphere" name="atmosphere-runtime" rev="2.2.9" conf="default"/>
        <dependency org="bsh" name="bsh" rev="1.3.0" conf="default"/>
        <dependency org="junit" name="junit" rev="4.12" conf="default"/>
        <dependency org="org.mockito" name="mockito-all" rev="1.10.19" conf="default"/>
        <dependency org="commons-fileupload" name="commons-fileupload" rev="1.2.2" conf="default"/>
        <dependency org="org.apache.commons" name="commons-exec" rev="1.3" conf="default"/>
        <dependency org="commons-io" name="commons-io" rev="2.4" conf="default"/>
        <dependency org="commons-jxpath" name="commons-jxpath" rev="1.3" conf="default"/>
        <dependency org="net.sf.ehcache" name="ehcache" rev="2.10.0" conf="default"/>
        <dependency org="org.glassfish.web" name="el-impl" rev="2.2" conf="default"/>
        <dependency org="net.sf.jsr107cache" name="jsr107cache" rev="1.1" conf="default"/>
        <dependency org="javax.mail" name="mail" rev="1.4.7" conf="default"/>
        <dependency org="io.netty" name="netty" rev="3.5.13.Final" conf="default"/>
        <dependency org="org.objenesis" name="objenesis" rev="2.1" conf="default"/>
        <dependency org="com.google.protobuf" name="protobuf-java" rev="2.4.1" conf="default"/>
        <dependency org="xalan" name="serializer" rev="2.7.2" conf="default"/>
        <dependency org="xalan" name="xalan" rev="2.7.2" conf="default"/>
        <dependency org="xerces" name="xercesImpl" rev="2.11.0" conf="default"/>
        <dependency org="org.primefaces.themes" name="casablanca" rev="1.0.10" conf="default"/>
        <dependency org="net.sourceforge.cssparser" name="cssparser" rev="0.9.20" conf="default"/>
        <dependency org="dom4j" name="dom4j" rev="1.6.1" conf="default"/>
        <dependency org="org.ini4j" name="ini4j" rev="0.5.4" conf="default"/>
        <dependency org="org.eclipse.jetty" name="jetty-websocket" rev="8.1.22.v20160922" conf="default"/>
        <dependency org="org.w3c.css" name="sac" rev="1.3" conf="default"/>
    </dependencies>
</ivy-module>

build.xml

<project name="SampleApp" default="usage" basedir="." xmlns:flyway="antlib:com.googlecode.flyway.ant" xmlns:ivy="antlib:org.apache.ivy.ant">
<property name="lib.dir" value="${basedir}/${web.dir}/WEB-INF/lib/"></property>
<target name="resolve" description="resolve dependencies with ivy">
        <ivy:resolve conf="default"/>
    </target>

    <target name="cleancache" description="Purge ivy cache">
        <ivy:cleancache/>
    </target>

    <target name="dependencytree" depends="resolve" description="Show dependency tree">
        <ivy:dependencytree />
    </target>

    <target name="retrieve" depends="resolve" description="Resolve and Retrieve with ivy">
        <ivy:retrieve conf="default" sync="true" type="jar,bundle" pattern="${lib.dir}[artifact]-[revision].[ext]"/>
        <!-- <ivy:cachepath pathid="default.classpath" /> -->
    </target>
</project>

如果您在关闭依赖项标记之前添加 <conflict manager="all"/> 行,您将不会有任何逐出的模块。像这样

    <conflict manager="all"/>
</dependencies>

引用自 here 的内置冲突管理器 all:

this conflicts manager resolve conflicts by selecting all revisions. Also called the NoConflictManager, it doesn't evict any modules.

我必须把conflict放在末尾,否则将无法正常工作。好像是 a bug in ivy.

只要确定这就是您想要的。引用自 here:

There are two things optimized during conflict resolution: download of artifacts and download of ivy files. The first is always ensured by ivy, i.e. artifacts of a module evicted will never be downloaded. The second is not as simple to handle because to know what are the conflicts ivy needs to know the dependency graph, and to know the dependency graph, it has to download ivy files. But ivy is highly optimized on this too, and it tries to evict modules as soon as possible. That's why the order of dependencies is important for download optimization. Indeed ivy traverses the dependency graph in the order in which dependencies are declared in the ivy files, and each time it encounters a dependency on a module, it first check if there is a conflict on this module, and if this is the case, it asks the conflict manager to resolve the conflict. Then if the module is evicted, it does not download its ivy file, and the whole branch is not traversed, which can saves a lot of time.

补充一下。

冲突部分完美运行。

<conflict manager="all"/>

无论如何,要找到关于它的信息并不容易,知道它的使用可以限于单个依赖项或者也可以使用通配符来 select 它们的一个子集可能很有​​用。就我而言,我是这样使用它的:

<conflict manager="all" module="module_1" org="org_1"/>

此外,还可以选择 select 使用不同经理的不同策略,更多信息请访问:http://ant.apache.org/ivy/history/2.0.0/settings/conflict-managers.html