Ivy: Fetching Javadocs and Sources
Asked Answered
C

1

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.

Culbertson answered 6/9, 2012 at 17:2 Comment(0)
C
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.

Culbertson answered 6/9, 2012 at 17:33 Comment(4)
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 <ivy:retrieve conf="compile"/>, I'll get the jar, the javadoc, and the sources. In that case, I only want the classes jar. If I say <ivy:retrieve conf="javadoc"/> I only want the Javadoc.Culbertson
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.Hessite
Nope. I tried that and both <ivy:retrieve conf="compile"/> and <ivy:retrieve conf="javadoc"/> 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.Culbertson
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.Circumrotate

© 2022 - 2024 — McMap. All rights reserved.