Vic Seedoubleyew
Vic Seedoubleyew

Reputation: 10526

Exclude dependencies by repository

Is there a way to tell Gradle to exclude all dependencies of a particular dependency, that would be pulled from a given repository ?

Removing that repository from the repositories list would not work, because I need that repository for other dependencies. But for one particular group, I want to exclude all dependencies that would come from that repository.

Something like :

dependencies {
    compile <my_first_package>
    compile('my_second_package') {
        exclude repository.name:thirdPartyRepository
    }

}

Upvotes: 0

Views: 1272

Answers (1)

MartinTeeVarga
MartinTeeVarga

Reputation: 10898

Looking at the source code, there are only two possibilities how to exclude a dependency and that is to exclude by module or a group. You can also mark a dependency not to fetch its transitive dependencies:

compile('my_second_package') {
    transitive = false
}

But that's all, there seems to be no way to remove dependencies based on repository. You can force versions using a ResolutionStrategy, maybe take a look if something there helps your use case.

As a workaround, maybe you can repackage the wrong dependency under a different name or version. Or you could use the transitive = false and simply add all the transitive dependencies that you actually want as declared dependencies.

Upvotes: 1

Related Questions