How to exclude dependency by version

(jeppe) #1

It seems you can only exclude a transitive dependency by group & name and not by version.

Is there a way to exclude a specific version of a dependency? I’m using a dependency that declares a dependency on an artifact already included but with a different version. Having both versions on the classpath breaks the build

(Tom Sheehan) #2


Have you seen the include/exclude samples on the page linked below?

Cheers, Tom

(jeppe) #3

Hi Tom,

Yes I did, but it also only mentions excluding by “name, group or both”, not by version.

I.e if I put

exclude group: ‘org.scala-lang’, module:‘scala-library’, version:‘2.9.1-1’

version: is ignored and it will exclude all scala-library, also version 2.9.1 which I actually need.

I’ve worked around this for now by adding it to the dependency that pulls in 2.9.1-1 but this seems not so nice if there will be more like these…


(Tom Sheehan) #4


I wonder if a ResolutionStrategy would be helpful to you.


(gretar arnason) #5

have you tried using:

configurations.all {
    resolutionStrategy {
        force 'org.scala-lang:scala-library:2.9.1'

(jeppe) #6

Yes it seems resolutionStrategy works just fine.

Thanks both for pointing me in the right direction :slight_smile: