Download package from other repositories when failed in first repositories

Hi Gradle team,
I am currently using the version of gradle6.6.1 and I have configured three repositories, assuming they are r1, r2, and r3. Most packages can be found in the first repository(r1), but there is one package. Assume it is com.sample:test:001. After this package is downloaded from the r1, it prompts a HTTP 403 CODE error, the build immediately comes to BUILD FAILED. But actually, this com.sample:test:001 can be found in r2 and r3. How do I configure it to continue after downloading r1 and prompting a 403 and try to get it from r2 and r3. If both fail, then return BUILD FAILED.
the build.gradle as:

buildscript {
	reporsitories {
		maven {
			url 'https://r1/nexus'
		}
		maven {
			url 'https://r2/nexus'
		}
		maven {
			url 'https://r3/nexus'
		}
	}
}

The error message as below:

Execution failed for task ':gateway:compileScala'.
> Could not resolve all files for configuration ':gateway:compileClasspath'.
    >Could not download test-001.jar (com.sample:test:001)
         > Could not get resource 'https://r1/nexus/com/sample/test/001/test-001.jar'
                > Could not GET  'https://r1/nexus/com/sample/test/001/test-001.jar'. Received status code 403 from server:

Yes, that’s expected.
If a repository does not have a dependency it has to answer with 404, then the next repository is checked.
If it answers with any other non-success code, the build fails as something with the repository is wrong.
Otherwise it could for example happen, that the first repository is down and while it would have had the dependency it is taken from the second repository which might be malicious or at least different and so on.
So if the repository does neither answer successfully nor with 404, the build fails intentionally to be on the safe side.

If you know which dependencies are not available in the first repository, you can use inclusive or exclusive repository content filters to control which dependencies are taken from which repositories.

Hi Vampire,
thank you for your reply. The situation I am currently facing is that downloading packages from r1 does indeed return an error of 403, but downloading from r2 and r3 is accessible. Gradle did not attempt to download packages from r2/r3, so I would like to know whether version 6.6.1 requires special adaptation: once one repository downloads and returns 40x, try to download from the other repositories

As I just explained, this is expected behavior and it also is the same in any Gradle version. To mitigate the current JCenter breakage either use repository content filters as I said, or move the broken repo to be the last one.

1 Like