Use public maven repository with ivy

33,917

Solution 1

You need to add an ivysettings.xml file with the following repositories listed (resolvers in ivy speak)

<ivysettings>
    <settings defaultResolver="chain"/>
    <resolvers>
        <chain name="chain">
            <ibiblio name="central" m2compatible="true"/>
            <ibiblio name="example" m2compatible="true" root="http://example.com/m2/"/>
        </chain>
    </resolvers>
</ivysettings>

In my opinion it makes more sense to separate the dependency declaration (ivy.xml) from the mechanism of retrieval (settings.xml). This is not needed in Maven because it only supports one type of repository.

If you want to get really fancy you can control which respository serves up a particular module:

<ivysettings>
    <settings defaultResolver="central"/>
    <resolvers>
        <ibiblio name="central" m2compatible="true"/>
        <ibiblio name="example" m2compatible="true" root="http://example.com/m2/"/>
    </resolvers>
    <modules>
        <module organisation="foo-bar" name="superwidgets" resolver="example"/>
    </modules>
</ivysettings>

Solution 2

I prefer chained resolvers that include SpringSource's EBR and Maven Central too, like this:

<ivysettings>
    <settings defaultResolver="spring-chain" />
    <resolvers>
        <chain name="spring-chain">
            <url name="com.springsource.repository.bundles.release">
                <ivy pattern="http://repository.springsource.com/ivy/bundles/release/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
                <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]" />
                <artifact pattern="http://repository.springsource.com/ivy/bundles/external/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
            </url>
            <ibiblio name="ibiblio" m2compatible="true"/>
        </chain>
    </resolvers>
</ivysettings>

Although I do not use them directly, I prefer to create and control my own local Ivy repository.

Share:
33,917
Adam Schmideg
Author by

Adam Schmideg

Updated on October 18, 2020

Comments

  • Adam Schmideg
    Adam Schmideg over 3 years

    I have an ivy.xml containing

    <dependencies>
      <dependency org="commons-lang" name="commons-lang" rev="2.4"/>
      <dependency org="foo-bar" name="superwidgets" rev="1.5"/>
    </dependencies>
    

    The whole superwidget stuff is hosted in a maven repository at http://example.com/m2/. The ivy documentation mentions resolvers, but it seems to assume an ivy repository. How can I add a single unofficial maven repository to my ivy settings to be used only by a single module? (Or put another way, what corresponds to maven's <repository> tag in ivy?) Nothing fancy, so I'd expect a one-liner in my ivy.xml.