0

Relatively new to Ivy here.

I have a growing list of projects that all publish to the same repository under the same organization. And I'm trying to find out how, if at all possible, I can declare dependencies from another project to artifacts created by all those projects.

My ivisettings.xml already has a resolver that points to that repository location. All artifacts in that repo are from the same organization. I trying to determine if there's a way to easily include artifacts in that location as dependencies from another project. I was hoping that I could do this using a wildcard for its names, like:

    <dependencies>
            <dependency org="my.org.name" name="**" rev="${current.iteration}" conf="master" />
    </dependencies>

But of course the above doesn't work. So, any pointer/comment/pointer suggestion would be welcomed. I can't be the first guy to want to do this, so there's got to be a way to do this and maybe I'm just not using the right keywords in my searches. Thanks.

4

1 回答 1

1

发布一个额外的 ivy 文件,将所有其他项目列为依赖项列表。

<ivy-module version="2.0">
    <info organisation="my.org.name" module="projects" revision="1.0.0" status="release" publication="20130215110241"/>

    <dependencies>
        <dependency org="my.org.name" name="projectA" rev="1.0.0"/>
        <dependency org="my.org.name" name="projectB" rev="1.0.0"/>
        <dependency org="my.org.name" name="projectC" rev="1.0.0"/>
        ..
        ..
    </dependencies>

</ivy-module>

为这个特殊的 ivy 模块创建单个依赖项,然后将其他项目工件作为传递依赖项拉入。

<dependency org="my.org.name" name="projects" rev="1.0.0"/>

增强

您可以更进一步,创建不同的配置来对项目的工件进行分类:

<ivy-module version="2.0">
    <info organisation="my.org.name" module="projects" revision="1.0.0" status="release" publication="20130215110241"/>

    <configurations>
        <conf name="web-apps" description="Projects which provide functionality for webapps"/>
        <conf name="standalone" description="Projects which provide functionality for stand-alone java apps"/>
    </configurations>

    <dependencies>
        <dependency org="my.org.name" name="projectA" rev="1.0.0" conf="webapps->default"/>
        <dependency org="my.org.name" name="projectB" rev="1.0.0" conf="standalone->default"/>
        <dependency org="my.org.name" name="projectC" rev="1.0.0" conf="webapps->default;standalone->default"/>
    </dependencies>

</ivy-module>

配置是一个非常有用的 ivy 功能​​。客户端构建可以使用映射来拉入与 webapp 或独立开发相关的工件。此功能类似于 Maven 中的“作用域”,但功能更强大。

更新:动态修订

发布“项目”模块时,您可能希望使用动态修订来简化维护。

<ivy-module version="2.0">
    <info organisation="my.org.name" module="projects"/>

    <dependencies>
        <dependency org="my.org.name" name="projectA" rev="latest.release"/>
        <dependency org="my.org.name" name="projectB" rev="latest.release"/>
        <dependency org="my.org.name" name="projectC" rev="latest.release"/>
        ..
        ..
    </dependencies>

</ivy-module>

发布任务将生成并推送使用每个项目的最新版本解析的 ivy 文件。

您仍然需要列出每个项目,但这实际上是一件好事。这意味着引入旧版本的“项目”模块将导致在某个时间点进行相同数量的修订。

生成常春藤文件

最后要完全自动化这个过程,使用可变数量的项目,也许你可以生成“项目”常春藤文件?

以下是您可以使用的groovy 代码段

<groovy>
    import groovy.xml.MarkupBuilder

    new File("build/ivy.xml").withWriter { writer ->
        def xml = new MarkupBuilder(writer)
        xml."ivy-module"(version:"2.0") {
            info(organisation:"my.org.name", module:"projects")
            dependencies() {
                new File("/path/to/projects/directory").listFiles().each { dir ->
                    dependency(org:"my.org.name", name:dir.name, rev:"latest.release")
                }
            }
        }
    }
</groovy>
于 2013-03-04T21:31:01.943 回答