Search code examples
javaeclipseapacheivyivyde

How do I include an Ivy Dependency in subversion repo


So, since I've been unable to find a way to resolve our dependency issues by including everything from external sources I've turned to Eclipse / IvyDE for ant / Ivy integration.

With that said, I normally include a lib like this:

<dependency org="org.jsoup" name="jsoup" rev="1.6.3"/>

However what if I want to look at something in our own intranet?

Example, if the folder holding the jar is somewhere like this:

https://prdsvn01.company.intra.net/repo/libName/

and I want to include lib.jar into my folder.

I've been relatively unable to find ivysettings.xml in this implementation of eclipse, nor am I confident that I'd be able to get it right if I could.

Could someone help me with this?


Solution

  • The following ivy settings file:

    <ivysettings>
        <settings defaultResolver="central"/>
    
        <resolvers>
            <ibiblio name="central" m2compatible="true"/>
    
            <url name="my-repo">
                <artifact pattern="http://myserver/myrepo/[organisation]/[artifact]/[revision]/[artifact].[ext]"/>
            </url>
        </resolvers>
    
        <modules>
            <module organisation="org.mycompany" resolver="my-repo"/>
        </modules>
    </ivysettings>
    

    Is configured to retrieve artifacts from Maven Central by default, and local artifacts from a HTTP server.

    Update

    ivy.xml

    Nothing special in the ivy file. Just declare the dependencies and which configuration to associate them with:

    <configurations>
        <conf name="compile" description="Required to compile application"/>
    </configurations>
    
    <dependencies>
        <!-- compile dependencies -->
        <dependency org="org.slf4j" name="slf4j-api" rev="1.6.4" conf="compile->default"/>
        <dependency org="org.mycompany" name="my-module" rev="1.0" conf="compile->default"/>
    
    </dependencies>
    

    Note:

    • It's ivy best practice to use configurations.

    build.xml

    <target name="resolve" dependencies="Resolve build dependencies">
        <ivy:resolve/>
    
        <ivy:report todir='build/reports' graph='false' xml='false'/>
    
        <ivy:cachepath pathid="compile.path" conf="compile"/>
        ..  
    </target>
    

    Notes:

    • The ivycachepath task transforms an ivy configuration into a populated ANT classpath. Very useful.
    • The ivy report task tells you the jars on the classpath(s)

    Ivy resolve build output

    All the magic is in the settings file. Running the build produces the following:

    [ivy:resolve]   found org.slf4j#slf4j-api;1.6.4 in central
    [ivy:resolve]   found org.mycompany#my-module;1.0 in my-repo
    ..
    [ivy:resolve] downloading http://repo1.maven.org/maven2/org/slf4j/slf4j-api/1.6.4/slf4j-api-1.6.4.jar ...
    ..
    [ivy:resolve] downloading http://myserver/myrepo/org.mycompany/my-module/1.0/my-module.jar ...
    

    Notes:

    • The my-repo resolver is used for modules with a "org.mycompany" groupId.
    • Everything else comes from the default resolver, Maven Central.