使用常春藤的公共maven存储库

时间:2011-01-29 09:04:26

标签: maven-2 artifactory ivy

我有ivy.xml包含

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

整个超级小部件内容托管在http://example.com/m2/的maven存储库中。常春藤文档mentions resolvers,但它似乎假设一个常春藤存储库。如何将单个非官方maven存储库添加到我的常春藤设置中,仅供单个模块使用? (换句话说,什么对应于常春藤中maven的<repository>标签?)没什么特别的,所以我希望我的ivy.xml中有一个单行。

3 个答案:

答案 0 :(得分:45)

您需要添加 ivysettings.xml 文件,其中列出了以下存储库(常春藤中的resolvers

<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>

在我看来,将依赖声明(ivy.xml)与检索机制(settings.xml)分开更有意义。 Maven不需要这样做,因为它只支持一种类型的存储库。

如果你想真正想象,你可以控制哪个资源库提供特定模块:

<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>

答案 1 :(得分:7)

我更喜欢包含SpringSource的EBR和Maven Central的链式解析器,如下所示:

<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>

虽然我不直接使用它们,但我更喜欢create and control my own local Ivy repository

答案 2 :(得分:0)

这里是试图保持常春藤默认行为并仅添加存储库maven.tmatesoft.com回购

的一种。
<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>