Sharing a library version between sub-projects

Continuing the discussion from Is it possible to pass variable from parent build.gradle to child build.gradle?:

As @luke_daley said, most of what you need to know about sharing dependencies is in documented under multi-project builds. But you can also share variables. For example, given a project like this:

root
 |- root.gradle
 \- sub
    \- sub.gradle

Your root.gradle can define variables in the dependencies block:

subprojects {
    dependencies {
        ext.springVersion = '3.1.1.RELEASE'
    }
}

Which can then be accessed in sub.gradle:

dependencies {
    compile "org.springframework:org.springframework.web:$springVersion"
}