Reputation: 24333
I want to tie gradle repositories to specific configurations in my build.gradle
file, e.g.:
repositories {
testCompile {
mavenCentral()
}
compile {
maven { url 'https://vetted-repo.example.com' }
}
}
I can't find a simple way to do this from the gradle documentation. Do I need to write my own plugin?
Upvotes: 4
Views: 2517
Reputation: 9999
As of Gradle 5.1 this is now possible, from the release notes:
It is now possible to match repositories to dependencies, so that Gradle doesn't search for a dependency in a repository if it's never going to be found there.
Example:
repositories { maven { url "https://repo.mycompany.com" content { includeGroupByRegex "com\\.mycompany.*" } } }
For the specific requirement of restricting a repository to a specific configuration such as compile
, you could use the onlyForConfigurations
property:
repositories {
maven {
url "https://vetted-repo.example.com"
content {
onlyForConfigurations "compile"
}
}
}
Upvotes: 5
Reputation: 28653
It is now possible to declare a repository filter in gradle. see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html#declaring_a_repository_filter this does exactly what you need here.
Upvotes: 1
Reputation: 28653
This is not supported by gradle at the moment. When resolving dependencies, gradle tries al listed repositories (from top to bottom) to resolve a dependency. Once the dependency is found it stops looking for it in other repositories
Upvotes: 2