English 中文(简体)
Use public maven repository with ivy
原标题:

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.

最佳回答

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>
问题回答

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.

Here s one that tries to keep Ivy s default behavior and just add on repository, the maven.tmatesoft.com repo

<ivysettings>
    <settings defaultResolver="default"/>

    <!-- These "magic lines" are pulled from: https://ant.apache.org/ivy/history/latest-milestone/tutorial/defaultconf.html -->
    <include url="${ivy.default.settings.dir}/ivysettings-public.xml"/>
    <include url="${ivy.default.settings.dir}/ivysettings-shared.xml"/>
    <include url="${ivy.default.settings.dir}/ivysettings-local.xml"/>
    <include url="${ivy.default.settings.dir}/ivysettings-main-chain.xml"/>
    <include url="${ivy.default.settings.dir}/ivysettings-default-chain.xml"/>
    <resolvers>
        <!-- Custom Repos here -->
        <ibiblio name="tmatesoft" m2compatible="true" root="https://maven.tmatesoft.com/content/repositories/releases/"/>
        <!--<filesystem name="internal">-->
            <!--<ivy pattern="${repository.dir}/[module]/ivy-[revision].xml"/>-->
            <!--<artifact pattern="${repository.dir}/[module]/[artifact]-[revision].[ext]"/>-->
        <!--</filesystem>-->
    </resolvers>
    <chain name="default" returnFirst="true" checkmodified="true" changingPattern=".*SNAPSHOT">
        <!-- These two are magic lines from the default conf -->
        <resolver ref="local"/>
        <resolver ref="main" />

        <!-- Custom Repos here -->
        <resolver ref="tmatesoft" />
    </chain>
    <modules>
        <module organisation="org.tmatesoft.hg4j" name=".*" resolver="tmatesoft"/>
    </modules>
</ivysettings>




相关问题
Derby gets stuck closing?

I ve got unit tests (in maven) that use derby. At the end of the test run, there is a very long pause, with these log messages before the pause. INFO: Closing Hibernate SessionFactory Nov 16, 2009 8:...

Execute goal on parent after children complete

I have a multi-module maven project (several levels of nesting). Normally, when I execute a maven build (like mvn install or whatever), maven will run all the goals for the parent project before ...

Including dependencies in a jar with Maven

Is there a way to force maven(2.0.9) to include all the dependencies in a single jar file? I have a project the builds into a single jar file. I want the classes from dependencies to be copied into ...

Java Equivalent of distcc

Distcc makes it easy to distribute a C or C++ compile job across a number of machines, and is a godsend for working with large, frequently-built codebases. An increasing number of our large projects ...

Maven Assembly Problem

I have a maven multiple-module project, which is giving me headaches in the assembly:assembly phase. I have a module which has an assembly defined in it which works fine when I invoke mvn assembly:...

热门标签