如何减去常春藤依赖集

How to subtract ivy dependency sets(如何减去常春藤依赖集)
本文介绍了如何减去常春藤依赖集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是将项目传递依赖关系划分为几个不交叉的集合:

My goal is to demarcate project transitive dependencies into several not crossing sets:

  • 系统(已存在于 j2ee 容器中的 jar;手动列出并带有明确的固定版本)
  • 提供(要复制到 j2ee 容器的 jar;手动列出)
  • ear(罐子装在 ear/lib 中,其余的)

下面列出的我目前的解决方案有一些缺点:

My current solution listed below has some shortcomings:

  • 必须从 ear conf 中逐一排除系统和提供的库
  • 尚未明确排除的新的第三方可传递部门可能会意外听到
  • 有时必须添加显式 override 复制库名称和版本
  • have to exclude system and provided libraries from ear conf one by one
  • new third-party transitive deps that weren't already explicitly excluded could accidentally get to ear
  • sometimes have to add explicit override duplicating library name and version

有什么办法可以消除这些缺点吗?

Is there some approach possible to eliminate these shortcomings?

如果能够以某种方式定义一个conf作为其他依赖集减法的结果(通过优雅的冲突解决),那就太好了:ear = 运行时 - 系统 - 提供.

It would be nice to be able somehow define one conf as a result of dependency sets subtraction of the others (with graceful conflict resolution): ear = runtime - system - provided.

当 IVY-982 得到修复.

寻找实际的解决方案来应用.

Looking for an actual solution to apply.

如果有解决方案,甚至愿意考虑切换到 gradle.

Even willing to consider switching to gradle if it has a solution.

<?xml version="1.0" encoding="UTF-8"?>
<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="example.com" module="parent"/>

    <configurations defaultconfmapping="compile->@;runtime->@;system->master;provided->runtime;ear->runtime;test->test(default)">
        <conf name="compile"/>
        <conf name="runtime" extends="compile"/>
        <conf name="ear" extends="runtime" description="Libs to be packed inside ear"/>
        <conf name="provided" description="Libs to copy to j2ee container"/>
        <conf name="system" description="Libs already present in j2ee container"/>
        <conf name="test" extends="ear,provided,system" description="Simulate container environment. Used by unit tests to catch dependency compatibility problems."/>
    </configurations>

    <dependencies>
        <dependency org="log4j" name="log4j" rev="1.2.15" force="true" conf="system"/>
        <dependency org="commons-collections" name="commons-collections" rev="3.1" force="true" conf="system"/>
        <dependency org="commons-lang" name="commons-lang" rev="2.2" force="true" conf="system"/>

        <dependency org="org.apache.velocity" name="velocity" rev="1.7" force="true" conf="provided"/>
        <dependency org="org.slf4j" name="slf4j-api" rev="1.5.6" force="true" conf="provided"/>
        <dependency org="org.slf4j" name="slf4j-log4j12" rev="1.5.6" force="true" conf="provided"/>
        <!-- ... -->

        <dependency name="module1" rev="latest.integration" conf="runtime,ear,provided,test"/>
        <dependency name="module2" rev="latest.integration" conf="runtime,ear,provided,test"/>
        <!-- ... -->

        <exclude org="commons-collections" conf="ear,provided"/>
        <exclude org="commons-lang" conf="ear,provided"/>
        <exclude org="org.apache.velocity" conf="ear"/>
        <!-- TODO: negation not working: https://issues.apache.org/jira/browse/IVY-982 -->
        <!--<exclude org="org.slf4j" conf="*, !provided"/>-->
        <exclude org="org.slf4j" conf="ear,test"/>
        <!-- ... -->

        <override org="org.slf4j" rev="1.5.6"/>
        <override org="commons-collections" module="commons-collections" rev="3.1"/>
        <override org="commons-lang" module="commons-lang" rev="2.2"/>
        <!-- ... -->
    </dependencies>

</ivy-module>

可以在 IVY-1443 附件中找到要试验的示例项目源.

Sample project sources to experiment with can be found in IVY-1443 attachment.

推荐答案

虽然提供的依赖项排除可以通过 Maven和Gradle,目前好像有没有办法用常春藤轻松实现它.

While provided dependencies exclusion is possible with Maven and Gradle, it seems that currently there is no way to easily achieve it with ivy.

更新

在某些情况下,可以使用中间诱导模块和 否定正则表达式 掩码:

In some cases the task can be worked around with intermediate induced module and negative regexp mask:

    <dependency org="com.company" name="root.module" conf="ear" rev="latest.integration">
        <exclude org="^(?!com.company).*$" matcher="regexp"/>
    </dependency>

但我们已经转移到 Gradle,因为 Ivy 似乎正在失去动力.

But we've already moved to Gradle as Ivy seems to be losing momentum.

这篇关于如何减去常春藤依赖集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How can create a producer using Spring Cloud Kafka Stream 3.1(如何使用Spring Cloud Kafka Stream 3.1创建制片人)
Insert a position in a linked list Java(在链接列表中插入位置Java)
Did I write this constructor properly?(我是否正确地编写了这个构造函数?)
Head value set to null but tail value still gets displayed(Head值设置为空,但仍显示Tail值)
printing nodes from a singly-linked list(打印单链接列表中的节点)
Control namespace prefixes in web services?(控制Web服务中的命名空间前缀?)