开发者

Can't get Apache Ivy not to download sources from Spring repository

In my project, I use Ivy to resolve dependencies. I use Spring's repository. The problem is that I don't want to download sources and licence/notice files. The settings which produce the problem are as follows:

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>

In Ivy's cache I see:

<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>
开发者_如何学Python

They are published for all the configs by defaults.

The question is: Why don't the source and licence files get excluded?


One workaround to achieve what I want (no sources, no licence/notice files) was to add type to <ivy:retrieve> task.

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

In this case, I don't need any <exclude> tags. This, however, doesn't answer the question why exclude didn't work in the first place.


Could you try (omit the nested exclude in the first dependency):

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

I have a feeling that the deeply nested exclude may be bugged. See here:

How to exclude commons logging dependency of spring with ivy?

It's just a hunch, everything seems very fine.


I've answered a similar question on Spring here.

In brief it amounts to:

1) Clear your ivy cache

2) Change your ivy settings file to use the Spring Maven repositories:

<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) Try change your configuration mapping from:

    <dependency .... conf="runtime->runtime"/>

to:

    <dependency .... conf="runtime->default"/>


Instead of trying to exclude all of the artifacts you don't want, try explicitly including only the artifacts you do want:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜