Apache Ivy 排除依赖项的标记
Posted
技术标签:
【中文标题】Apache Ivy 排除依赖项的标记【英文标题】:Apache Ivy exclude tag for dependencies 【发布时间】:2016-11-20 12:26:15 【问题描述】:当我从 selenium 下载依赖项时,我想排除 Apache Ivy 解析中的一些 jar,例如 selenium-safari-driver-2.53.1.jar、selenium-edge-driver.2.53.1.jar、selenium-support。罐子等。但是,经过反复尝试并尝试了匹配器和类型的不同组合,它似乎不起作用。下面是我的 Ivy.xml
<configurations>
<conf name="core" description="only ivy jar, without any dependencies"/>
<conf name="standalone" extends="core" description="to launch in standalone mode (from command line)"/>
<conf name="default" extends="core" description="full ivy with all dependencies"/>
<conf name="test" description="dependencies used for junit testing ivy" visibility="private"/>
<conf name="source" description="ivy sources"/>
</configurations>
<publications>
<artifact name="ivy" type="jar" conf="core"/>
<artifact name="ivy" type="source" ext="jar" conf="source"/>
</publications>
<dependencies>
<dependency org="org.seleniumhq.selenium" name="selenium-java" rev="2.53.1"/>
<dependency org="org.testng" name="testng" rev="6.8"/>
<exclude type="javadoc" ext="*" conf="*"/>
<exclude type="source" ext="*" conf="*"/>
<exclude type="license" ext="*" conf="*"/>
<exclude org="seleniumhq.selenium" module="safari-driver" matcher="regexp" />
</dependencies>
请告诉我如何有效地包含这些排除项。
【问题讨论】:
【参考方案1】:Ivy 将解决所有依赖项。排除项可用于确定特定 ivy 配置的内容。
您需要包含配置映射,一般您只需使用远程模块的“默认”配置,这将排除源和 javadocs:
<dependency org="??" name="??" rev="???" conf="mylocalconf->default">
示例
├── build.xml
├── ivy.xml
└── target
└── lib
├── cglib-nodep-2.1_3.jar
├── commons-codec-1.10.jar
├── commons-exec-1.3.jar
├── commons-io-2.4.jar
├── commons-logging-1.2.jar
├── gson-2.3.1.jar
├── guava-19.0.jar
├── htmlunit-driver-2.21.jar
├── httpclient-4.5.1.jar
├── httpcore-4.4.3.jar
├── jna-4.1.0.jar
├── jna-platform-4.1.0.jar
├── netty-3.5.7.Final.jar
├── selenium-api-2.53.1.jar
├── selenium-java-2.53.1.jar
├── selenium-leg-rc-2.53.1.jar
└── selenium-support-2.53.1.jar
ivy.xml
<ivy-module version="2.0">
<info organisation="com.myspotontheweb" module="demo"/>
<configurations>
<conf name="compile" description="Required to compile application"/>
<conf name="runtime" description="Additional run-time dependencies" extends="compile"/>
<conf name="test" description="Required for test only" extends="runtime"/>
</configurations>
<dependencies>
<!-- compile dependencies -->
<dependency org="org.seleniumhq.selenium" name="selenium-java" rev="2.53.1" conf="compile->default">
<exclude org="org.seleniumhq.selenium" name="selenium-chrome-driver"/>
<exclude org="org.seleniumhq.selenium" name="selenium-edge-driver"/>
<exclude org="org.seleniumhq.selenium" name="selenium-firefox-driver"/>
<exclude org="org.seleniumhq.selenium" name="selenium-ie-driver"/>
<exclude org="org.seleniumhq.selenium" name="selenium-remote-driver"/>
<exclude org="org.seleniumhq.selenium" name="selenium-safari-driver"/>
</dependency>
<!-- test dependencies -->
<dependency org="org.testng" name="testng" rev="6.8" conf="test->default"/>
</dependencies>
</ivy-module>
注意事项:
配置“runtime”和“test”是“compile”的超集 每个依赖项都有一个配置映射 单个依赖项的本地排除项build.xml
<project name="demo" default="resolve" xmlns:ivy="antlib:org.apache.ivy.ant">
<target name="resolve">
<ivy:resolve/>
<ivy:retrieve pattern="target/lib/[artifact]-[revision](-[classifier]).[ext]" conf="compile"/>
</target>
</project>
注意事项:
“target/lib”目录仅填充“编译”配置中的依赖项。【讨论】:
以上是关于Apache Ivy 排除依赖项的标记的主要内容,如果未能解决你的问题,请参考以下文章
如何让 Ivy 将我的依赖项的依赖项捆绑到他们自己的 jar 中?
具有变量的 maven 依赖项的 Ivy/sbt 错误,是不是有修复?