在我的项目中,我使用Ivy来解决依赖关系。我使用Spring的存储库。问题是我不想下载来源和许可证/通知文件。产生问题的设置如下:
ivyconf.xml
<ivysettings>
<settings defaultResolver="default" />
<resolvers namespace="apache">
<chain name="default" returnFirst="true">
<url name="com.springsource.repository.bundles.release">
<!--<ivy pattern="http://repository.springsource.com/ivy/bundles/release/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />-->
<!-- or this one? -->
<ivy pattern="http://repository.springsource.com/ivy/bundles/release/[organisation]/[module]/[revision]/ivy-[revision].xml" />
<artifact pattern="http://repository.springsource.com/ivy/bundles/release/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
</url>
<url name="com.springsource.repository.bundles.external">
<!--<ivy pattern="http://repository.springsource.com/ivy/bundles/external/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />-->
<ivy pattern="http://repository.springsource.com/ivy/bundles/external/[organisation]/[module]/[revision]/ivy-[revision].xml" />
<artifact pattern="http://repository.springsource.com/ivy/bundles/external/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
</url>
</chain>
</resolvers>
</ivysettings>
ivy.xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="file:///home/nikem/workspace/ark/test.xsl"?>
<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="com.foo-corp" module="bar" />
<configurations>
<conf name="runtime" description="Modules needed for running the application"/>
</configurations>
<dependencies>
<dependency org="org.apache.batik" name="com.springsource.org.apache.batik.dom.svg" rev="1.7.0" conf="runtime->runtime">
<exclude type="src" ext="jar" conf="runtime"/>
</dependency>
<dependency org="org.apache.batik" name="com.springsource.org.apache.batik.bridge" rev="1.7.0" conf="runtime->runtime" />
<exclude type="src" ext="jar" conf="runtime"/>
<exclude type="javadoc" ext="jar" conf="runtime"/>
<exclude type="license" ext="txt" conf="runtime"/>
</dependencies>
</ivy-module>
build.xml
<project name="yunowork" default="ivy-runtime" basedir="." xmlns:ivy="antlib:org.apache.ivy.ant">
<property name="run.lib.dir" value="projlib"/>
<property name="lib.dir" value="lib"/>
<taskdef resource="org/apache/ivy/ant/antlib.xml" uri="antlib:org.apache.ivy.ant" classpath="${lib.dir}/ivy.jar"/>
<target name="clean-lib" description="Removes all libraries">
<delete dir="${run.lib.dir}" includes="*.jar"/>
</target>
<target name="ivy-clean-cache" description="Cleans Ivy cache">
<ivy:cleancache />
</target>
<target name="ivy-runtime">
<ivy:settings file="ivyconf.xml"/>
<ivy:resolve file="ivy.xml"/>
<ivy:retrieve pattern="${run.lib.dir}/[artifact].[ext]" conf="runtime"/>
</target>
</project>
在Ivy的缓存中,我看到:
<publications>
<artifact name="com.springsource.org.apache.batik.dom.svg"/>
<artifact name="com.springsource.org.apache.batik.dom.svg-sources" type="src" ext="jar"/>
<artifact name="license" type="license" ext="txt"/>
<artifact name="notice" type="license" ext="txt"/>
</publications>
默认情况下,会为所有配置发布它们。
问题是:为什么不排除源文件和许可证文件
实现我想要的(无来源,无许可证/通知文件)的一个解决方法是将type
添加到<ivy:retrieve>
任务中。
<ivy:retrieve pattern="${run.lib.dir}/[artifact].[ext]" type="jar" />
在这种情况下,我不需要任何<exclude>
标签。然而,这并不能回答为什么排斥一开始就不起作用的问题。
你能尝试一下吗(省略第一个依赖项中的嵌套exclude):
<dependencies>
<dependency org="org.apache.batik" name="com.springsource.org.apache.batik.dom.svg" rev="1.7.0" conf="runtime->runtime"/
<dependency org="org.apache.batik" name="com.springsource.org.apache.batik.bridge" rev="1.7.0" conf="runtime->runtime" />
<exclude type="src" ext="jar" conf="runtime"/>
<exclude type="javadoc" ext="jar" conf="runtime"/>
<exclude type="license" ext="txt" conf="runtime"/>
</dependencies>
我有一种感觉,嵌套很深的exclude可能被窃听了。请参阅此处:
如何排除spring与ivy的commons日志依赖性?
这只是一种预感,一切似乎都很好。
我在这里回答了关于Spring的类似问题。
简而言之,它相当于:
1) 清除常春藤缓存
2) 更改ivy设置文件以使用SpringMaven存储库:
<ivysettings>
<settings defaultResolver="chain"/>
<resolvers>
<chain name="chain">
<ibiblio name="central" m2compatible="true"/>
<ibiblio name="spring-release" root="http://repository.springsource.com/maven/bundles/release" m2compatible="true"/>
<ibiblio name="spring-external" root="http://repository.springsource.com/maven/bundles/external" m2compatible="true"/>
</chain>
</resolvers>
</ivysettings>
3) 尝试更改您的配置映射:
<dependency .... conf="runtime->runtime"/>
至:
<dependency .... conf="runtime->default"/>
与其尝试排除所有您不想要的工件,不如尝试显式地只包括您想要的工件:
<dependency org="org.apache.batik" name="com.springsource.org.apache.batik.dom.svg" rev="1.7.0" conf="runtime->runtime">
<artifact name="com.springsource.org.apache.batik.dom.svg"/>
</dependency>