无法让Apache Ivy从Spring存储库下载源代码

时间:2011-06-28 12:04:14

标签: ant repository ivy

在我的项目中,我使用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>

在常春藤的缓存中,我看到:

<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>

默认情况下,它们会针对所有配置发布。

问题是:为什么不排除源文件和许可证文件?

4 个答案:

答案 0 :(得分:2)

实现我想要的(没有来源,没有许可/通知文件)的一种解决方法是将type添加到<ivy:retrieve>任务。

<ivy:retrieve pattern="${run.lib.dir}/[artifact].[ext]" type="jar" />

在这种情况下,我不需要任何<exclude>标记。但是,这并没有回答为什么排除首先不起作用的问题。

答案 1 :(得分:1)

您可以尝试(省略第一个依赖项中的嵌套排除):

<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>

我觉得深层嵌套的排除可能会被窃听。见这里:

How to exclude commons logging dependency of spring with ivy?

这只是一种预感,一切看起来都很好。

答案 2 :(得分:1)

我在Spring here上回答了类似的问题。

简而言之,相当于:

1)清除你的常春藤缓存

2)更改常春藤设置文件以使用Spring Maven存储库:

<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"/>

答案 3 :(得分:0)

不要试图排除您不想要的所有工件,而是尝试仅显示您想要的工件:

<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>
相关问题