Gradle tries to download artifacts from prod and dev repos

I have the following setup in my build.gradle file:
repositories {
maven {
url = ‘https://somewebsite…/maven-prod/’
credentials {
username = “…”
password = “…”
}
}
}

However when Gradle cannot find a particular artifact maven-prod repo above it then searches in the following repo:
https://somewebsite…/maven-dev/
I don’t explicitly set this anywhere. Is this something that’s controlled in Gradle? How can I disable it? I only want maven-prod to be checked and not maven-dev.

Are you applying any plugins that may be configuring repositories?

Here’s a quick little task that will dump out the configured repository urls.

task dumpRepos {
    doLast {
        println repositories.collect { it.url }.join( '\n' )
    }
}

Chris, this helped. I found the offending plugin. Thank you for your help.

Chris, additional question: is it possible to configure build.gradle file to enforce that only prod repo is checked? I’m afraid that even if this particular plugin is fixed then some other plugin can introduce a similar problem.

If your intent is that you want specific modules to only be resolved from a specific repository, then using “exclusive content filtering” might be want you need.

You can also add include/exclude filters per repository.

Another way would be to define the repository in the settings script in the dependencyResolutionManagement block and also set repositoriesMode.set(FAIL_ON_PROJECT_REPOS), then the build will fail if someone or something tries to add a different repo.

What I was thinking is something like: remove all repositories added by plugins and add all of the repositories that I want to use. Do you have an example for how to do this?

That would functionally be the same as declaring your repos in the settings script and using repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS). That way you only get a warning instead of a failure.

@Vampire I was unaware of this feature, thanks for pointing it out.

1 Like

Looks like dependencyResolutionManagement has been added in Gradle 6.8. I’m still on 6.6.1. Is there any solution available for my version of Gradle?

You are right, this was added in 6.8.
Is there anything preventing you to upgrade Gradle?
6.6.1 → 6.8 should hopefully be a pretty easy upgrade without problems.

If you really need a 6.6.1 solution you can probably do something like this:

repositories.all {
    if ((this !is UrlArtifactRepository) || ("$url" != "my://allowed/url")) {
        repositories.remove(this)
    }
}

Disclaimer: that code is untested :slight_smile: