DaveyDaveDave
DaveyDaveDave

Reputation: 10572

How do I depend on both releases and snapshots from Artifactory in Gradle?

I feel like I'm missing something with Artifactory's 'virtual repos' concept. I'm new to both Artifactory and Gradle, having used Nexus and Maven before, and I don't remember ever encountering these types of issues in the past.

I feel like I have a fairly normal scenario, where I need mostly release dependencies, with a few snapshot dependencies during development.

The release dependencies are available from the virtual repo 'libs-release' (which includes 'libs-release-local', amongst other repos), and the snapshots are available in 'libs-snapshot'.

What I'm confused about is how I'm supposed to define this in Gradle, with the Artifactory plugin? From the docs and examples, I think I need something like:

artifactory {
  contextUrl = 'http://my-artifactory/artifactory'

  resolve {
    repository {
      repoKey = 'all-my-libs'
    }
  }
}

But that feels wrong - what's the point in the separate repos if I just lump them all together to use them? Comments in the answer to this question back up my concerns. That question talks about the /repo virtual repository, which for some reason isn't available to me. I get a 403 Forbidden if I try to use it.

Without Artifactory, I'd define multiple repositories like:

repositories {
  // other repos...
  maven { url 'http://my-artifactory/releases' }
  maven { url 'http://my-artifactory/snapshots' }
}

but when I include the Artifactory plugin, it seems that the repositories closure is either ignored or butchered in some way - with something similar to the example above, and without the resolve closure, Gradle seems to only be attempting to get dependencies from the http://my-artifactory/snapshots repo, and failing (with 409 Conflict) when it tries to find release dependencies.

So - what am I missing? Should I be asking the person with admin rights on Artifactory to create a new virtual repo combining libs-release and libs-snapshot? Or something else?

Upvotes: 3

Views: 1407

Answers (2)

Dror Bereznitsky
Dror Bereznitsky

Reputation: 20376

The resolution repository can be used in order to override all other repository definitions and making sure all artifacts are being resolved from a central repository.
This central repository is usually a virtual repository in Artifactory. Using a virtual repository has many benefits, for example it allows you to control which artifacts are can be resolved (by adding/removing repositories from the virtual) without changing the URL used in the build scripts.

Another use of the resolution repository is when the plugin is used for publishing build information to Artifactory. A list of all dependencies resolved during the build is collected as part of the build information.

Do notice, this is an optional feature. You may continue using the regular Gradle way of configuring repositories instead.

Upvotes: 2

John Ament
John Ament

Reputation: 11723

You're getting a 409 Conflict because someone configured your artifactory to reject release requests on the snapshot repo. A virtual repo is your easiest solution, since it can aggregate without these rules necessarily applying.

/repo is a custom repo someone created in that other post you mention. It won't exist unless someone explicitly created it in your artifactory env.

Upvotes: 0

Related Questions