How to exclude dependency by version

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

1 Like

Jeppe,

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

http://gradle.org/docs/current/dsl/org.gradle.api.artifacts.dsl.DependencyHandler.html

Cheers, Tom

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…

/Jeppe

Jeppe,

I wonder if a ResolutionStrategy would be helpful to you.

Tom

have you tried using:

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

Yes it seems resolutionStrategy works just fine.

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

/Jeppe