我的目标是将项目可传递依赖项划分为几个不交叉的集合:
-
系统(jar已经存在于j2ee容器中;以明确的固定版本手动列出)
-
提供(要复制到j2ee容器的jar;手动列出)
-
ear(罐子装在ear/lib里面,其余的)
下面列出的我目前的解决方案有一些缺点:
-
必须从ear conf中逐个排除系统和提供的库
-
尚未明确排除的新的第三方可传递dep可能会意外进入耳朵
-
有时必须添加显式
override
复制库名称和版本
有没有办法消除这些缺点?
如果能够以某种方式将一个conf定义为依赖集减去其他conf的结果(具有优雅的冲突解决方案),那就太好了:
ear=运行时-系统提供
.
大概
<conf name="ear" extends="runtime,!system,!provided"/>
当
IVY-982
得到修复。
寻找一个实际的解决方案来应用。
如果有解决方案,甚至愿意考虑改用gradle。
<?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
附件