Mark Fisher
Mark Fisher

Reputation: 9886

How do I resolve flatDir transient dependencies when publishing to an ivy repository in gradle?

I have a project built by gradle that publishes an artifact to a local ivy repository. Historically, we have used gradle purely with flatDir repositories, as we want to keep everything local. However, I'm starting to see the benefit of using ivy over copying the generated artifacts everywhere.

I can publish the artifact to ivy easily, but other projects that use the repository to pull this artifact in fail on its transient flatDir dependencies.

I'm trying to work out the best way to handle these transient dependencies. It's clear they are needed by anyone using the artifact as they have classes that artifact uses. Should I publish the transient dependencies with my artifact to ivy? What's the best way to do this?

I've tried (what I consider a hack) declaring the jars in the flatLib dir as artifacts themselves with:

group 'utils'

repositories {
    flatDir {
        dirs 'lib'
        name 'librepo'
    }
}

dependencies {
    compile ":antlr:3.4"
    // ...
}

artifacts {
    project.repositories.librepo.dirs.each { dir ->
        dir.eachFile {
            if (it.isFile()) {
                archives file(it)
            }
        }
    }
}

However, projects that include the artifact fail because the flatDir files are uploaded to the same group as the main artifact (in this case, 'utils'), but are defined with no group in the dependencies section, and so the entries in ivy.xml have no org value, i.e.

<dependency org="" name="antlr" rev="3.4" conf="compile->default"/>

I think I'm missing something, any help would be appreciated on how to mix flatDir and ivy.

Should I migrate the flatDir dependencies to ivy so they resolve correctly, and I can then change my build to use just the ivy repository it's publishing to as a source as well? I can't really think of a better way, but if I do this, it'll have quite an impact in that every dependency will have to move out of the main project dir's lib dir, to ivy, and I only really want to use the ivy repository to manage our generated artifacts, not third party libraries.

Upvotes: 1

Views: 997

Answers (1)

Mark Fisher
Mark Fisher

Reputation: 9886

For completeness, I couldn't find a decent solution to this and ended up moving all the lib/ jars to ivy too with the help of this article. Still, this question ended up earning me the tumbleweed award!

Upvotes: 1

Related Questions