I'm getting a wrong version of a dependency

I’m getting a different (newer) version of an artifact in my output war file than the one I asked for:

project.ext.springVersion = ‘3.1.2.RELEASE’

dependencies {

compile group: ‘org.springframework’, name: ‘spring-core’, version: springVersion

compile group: ‘org.springframework’, name: ‘spring-context’, version: springVersion

What I’m getting though is spring-context 3.2.0.M2 (and other Spring artifacts). Here’s a fragment of gradle dependency:

compile - Classpath for compiling the main sources. ±-- org.springframework:spring-webmvc:3.1.2.RELEASE [default] |

±-- org.springframework:spring-asm:3.1.2.RELEASE [compile,master,runtime] |

±-- org.springframework:spring-context-support:3.1.2.RELEASE [compile,master,runtime] |

|

±-- org.springframework:spring-context:3.2.0.M2 [compile,master,runtime] […] — org.springframework:spring-core:3.2.0.M2 [default] () — org.springframework:spring-context:3.2.0.M2 [default] ()

Why? How can I fix this?

Well, this helps, but is this really the way to do it?

configurations.all {

resolutionStrategy {

failOnVersionConflict()

force group: ‘org.springframework’, name: ‘spring-core’, version: springVersion

} }

Do you have another dependency that transitively depends on Spring 3.2.0.M2?

Yes, the it’s pulled in by spring data mongodb.

It’s one way to do it, although you don’t necessarily need the ‘failOnVersionConflict()’. For dependencies that you declare yourself, a simpler solution is ‘dependencies { compile “org.springframework:spring-core:$springVersion” { force = true } }’.

Hi Peter. What’s the proper way then?

I already showed another way. Did you see my edit?

I didn’t, now I do, thanks. Why shouldn’t this be the default behaviour?

I think it should, but not everyone shares this opinion. Besides, it’s probably too late to change the default.

Okay, thanks.

Peter, if you actually Reply below my question (with the force thing), I will be able to mark the question as answered.

Unfortunately, only moderators can mark topics as answered. I’ll do that now.