A way to redirect all the transivite dependencies to an Artifactory repository?


(Josselin Pierre) #1

Hi everyone !

Is there a way to direct all the transivite dependencies to an Artifactory repository?

Here’s the setup : I have on my work network an Artifactory repository, proxying all the maven repositories. My build script itself download it’s dependencies from that Artifactory just fine. However, it seems that the gradle plugins are downloading their own dependencies directly from maven.repo1.

Is there a way to redirect these artifacts resolution ? I’m pretty sure I’m not the first one with that kind of issue…


(Peter Niederwieser) #2

I’m not aware of a one-stop solution. However, plugins usually don’t declare their own repositories. Instead, they rely on the repositories declared in the build script. That’s certainly how Gradle’s bundled plugins work.


(Luke Daley) #3

You can remove repositories from the repository list if something is adding one you don’t want.

def coporateRepoUrl = "http://repo.gradle.org/gradle/repo"
repositories {
    all { ArtifactRepository repo ->
        if (!(repo instanceof MavenArtifactRepository) || repo.url.toString() != coporateRepoUrl) {
            logger.warn "Repository ${repo.url} removed. Only $coporateRepoUrl is allowed"
            remove repo
        }
    }
      maven { url coporateRepoUrl }
}

(Peter Niederwieser) #4

An then something similar for build script repositories, I guess.


(Luke Daley) #5

Good point, you’d need to do this:

buildscript {
  def coporateRepoUrl = "http://repo.gradle.org/gradle/repo"
  configure([project.repositories, repositories]) {
      all { ArtifactRepository repo ->
          if (!(repo instanceof MavenArtifactRepository) || repo.url.toString() != coporateRepoUrl) {
              logger.warn "Repository ${repo.url} removed. Only $coporateRepoUrl is allowed"
              remove repo
          }
      }
      maven { url coporateRepoUrl }
  }
}

(Josselin Pierre) #6

Thanks for all the replies, I’ll give it a try. :slight_smile:

I’m not aware of a one-stop solution. However, plugins usually don’t declare their own repositories. Instead, they rely on the repositories declared in the build script. That’s certainly how Gradle’s bundled plugins work.

That’s what I was expecting too, but apparently I ran into some beta plugin. I’ll track it down and kill its repositories declarations. =)