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.

1 Answer 1

1

Publish an extra ivy file that lists all the other projects as a list of dependencies.

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

Creating a single dependency against this special ivy module will then pull in the other project artifacts as transitive dependencies.

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

Enhancement

You could go one further and create different configurations to categorize your projects' artifacts:

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

Configurations are an extremely useful ivy feature. Client builds can use mappings to pull in artifacts associated with either webapp or standalone development. This feature is similar to "scopes" in Maven but much more powerful.

Update: Dynamic revisions

When publishing the "projects" module, you might want to use dynamic revisions to simplify maintenance.

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

The publish task will generate and push an ivy file resolved with the latest version of each project.

You will still need to list each project, but this is in fact a good thing. It means pulling in older versions of the "projects" module will result in same number of revisions at a point in time.

Generate ivy file

Finally to completely automate this process, using a variable number projects, perhaps you could generate the "projects" ivy file?

The following is a groovy snippet that you could use:

<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>
6
  • Hi Mark, thanks for the quick response! I was looking for a solution that doesn't require me to list out all the projects I need. Reason being: it's a big development team, and we're early enough in the development that we have had to set up new projects every few months. And I was hoping to avoid having an ivy.xml with static dependency list, because I don't want us to maintain it. I hope that provides some clarifications to what I'm trying to do here. Commented Mar 4, 2013 at 22:05
  • @YahyaCahyadi the point of Ivy is to have precise information about project dependencies. What you want to do undermines that. Commented Mar 4, 2013 at 22:47
  • @YahyaCahyadi Added an idea to generate your ivy file Commented Mar 5, 2013 at 0:26
  • Thanks @GeoffReedy. I won't disagree with you that my needs are quite suspicious here. It probably won't make it to the list of best practices. But I think it makes sense for my use case. Commented Mar 5, 2013 at 4:39
  • Thanks @MarkO'Connor! I had a similar idea in mind but thought I'd keep it as a last resort. But based on what you've told me so far, it looks like ivy doesn't have an off-the-shelf solution for me (probably because, as suggested by @GeoffReedy, that's not how ivy's supposed to be used). So I think I'll go with the dynamic ivy file generation. Thanks again for all the pointers! Commented Mar 5, 2013 at 4:52

Not the answer you're looking for? Browse other questions tagged or ask your own question.