8

I'm fairly new to Ivy, but have gotten it to work with jar dependencies. The problem is trying to set it up, so I can fetch javadocs and sources independently of jars.

I have a simple test project, but no matter what I'm doing, I'm fetching the jar with the class files in it.

I have the following ivy.xml file:

<ivy-module version="1.0">
    <info
        organisation="com.vegicorp"
        module="test"
        revision="1.0"
        status="release"/>

    <configurations>
        <conf name="default" visibility="public" extends="runtime,master"/>
        <conf name="master" visibility="public"/>
        <conf name="compile" visibility="public"/>
        <conf name="provided" visibility="public"/>
        <conf name="runtime" visibility="public" extends="compile"/>
        <conf name="test" visibility="private" extends="runtime"/>
        <conf name="system" visibility="public"/>
        <conf name="sources" visibility="public"/>
        <conf name="javadoc" visibility="public"/>
        <conf name="optional" visibility="public"/>
    </configurations>

    <dependencies>
        <dependency org="commons-logging" name="commons-logging" rev="1.1.1"
            conf="compile->default"/>
        <dependency org="commons-logging" name="commons-logging" rev="1.1.1"
            conf="sources->default">
            <artifact name="commons-logging" type="sources" ext="jar"/>
        </dependency>
        <dependency org="commons-logging" name="commons-logging" rev="1.1.1"
            conf="javadoc->default">
            <artifact name="commons-logging" type="javadoc" ext="jar"/>
        </dependency>
    </dependencies>
</ivy-module>

And the following build.xml:

<project name="ivy-test" default="default" basedir="."
    xmlns:ivy="http://ant.apache.org/ivy">

    <property name="ivy.dir" value="${basedir}/ivy.dir"/>
    <import file="${ivy.dir}/ivy.tasks.xml"/>

    <property name="target.dir" value="${basedir}/lib"/>
    <target name="-resolve">
        <ivy:resolve/>
    </target>

    <target name="clean">
        <delete dir="${target.dir}"/>
        <ivy:cleancache/>
    </target>

    <target name="default"
        depends="-resolve">

        <fail message="ivy.conf is not defined">
            <condition>
                <not>
                    <isset property="ivy.conf"/>
                </not>
            </condition>
        </fail>

        <delete dir="${target.dir}"/>
        <mkdir dir="${target.dir}"/>
        <ivy:retrieve conf="${ivy.conf}"
            pattern="${target.dir}/[artifact]-[revision].[ext]"/>
    </target>
</project>

At the command line, I'll type:

$ ant -Divy.conf=compile

And, that should download the jarfile with the classes.

However if I type it this:

$ ant -Divy.conf=sources

I want the jar file that contains the sources and not the classes, and when I type this:

$ ant -Divy.conf=javadoc

I want the jar file that contains the javadoc and not the sources.

I'm pretty sure it's my ivy.xml that's not quite right. I originally tried this:

<dependencies>
    <dependency org="commons-logging" name="commons-logging" rev="1.1.1">
        <artifact name="commons-logging" type="jar" ext="jar" conf="compile->default"/>
        <artifact name="commons-logging" type="sources" ext="jar" conf="sources->default"/>
        <artifact name="commons-logging" type="javadoc" ext="jar" conf="javadoc->default"/>
    </dependency>

That downloaded the jar, the sources, and javadoc, but all at once no matter which configuration I tried.

David W.
  • 105,218
  • 39
  • 216
  • 337

1 Answers1

5

Okay, I think I've figured it out. I was over thinking this whole process. My <dependencies> section should look like this:

<dependencies>
    <dependency org="commons-logging" name="commons-logging" rev="1.1.1"
        conf="javadoc->javadoc;sources->sources;compile->default"/>
</dependencies>

This maps my javadoc to Maven's javadoc and my sources to Maven's sources. When I mapped conf="sources->default", it was mapping my sources to Maven's default which is the compile dependencies.

I can specify all the configurations in one line, and I don't need separate <artifact> entities.

David W.
  • 105,218
  • 39
  • 216
  • 337
  • I found if I don't map my configuration to default, I get everything whether I want it or not. In your example, if I said ``, I'll get the jar, the javadoc, and the sources. In that case, I only want the classes jar. If I say `` I only want the Javadoc. – David W. Sep 07 '12 at 13:14
  • yeah right :) I forgot that default is the maven scope for the single jar. So it could be shortened to conf="javadoc;sources;compile->default" I think. – oers Sep 07 '12 at 13:32
  • 1
    Nope. I tried that and both `` and `` will both pull the standard jar with the classes. The problem is that you have to map your `compile` to Maven's `default`, your `javadoc` to Maven's `javadoc`, and your `sources` to Maven's `sources`. Thus the `conf="compile->default;sources->sources;javadoc->javadoc"`. This maps all three of my configurations to all three of Maven's scopes. This is quite confusing. I worked on it for a few hours, asked at SO, and worked on it another hour before I figured it out. – David W. Sep 07 '12 at 15:15
  • 1
    It's possible to specify `configurations defaultconfmapping="compile->master;runtime->default;sources->@;javadoc->@"` and then just use dependencies with `conf="compile,javadoc,sources"` without unwanted extra mappings. – Vadzim Oct 25 '13 at 12:10