How reuse a common 'group' and 'version' attributes for many 'names' (dependencies)


If I have

group: 'org.springframework', name: 'spring-core', version: '2.5',
group: 'org.springframework', name: 'spring-aop', version: '2.5',
group: 'org.springframework', name: 'spring-mvc', version: '2.5'



Is there a way for both styles, to define and reuse the group and version attributes? Something like this:

group: 'org.springframework', 
names: ['spring-core', 'spring-aop','spring-mvc'], 
version: '2.5'

Something similar for the other approach

It would reduce a lot more the configuration.

is possible this? If yes. How?

Thanks in advance.

You could use some Groovy magic to accomplish this.

dependencies {
    ['spring-core', 'spring-aop','spring-mvc'].each {
        compile "org.springframework:$it:2.5"

Hello Mark

Thanks a lot. Below my complete code for the community.

ext {
	slf4jVersion = '1.7.10'
	logbackVersion = '1.1.2'	
	springframeworkVersion = '4.0.7.RELEASE'

dependencies {

	compile "org.slf4j:slf4j-api:${slf4jVersion}",
	['spring-core', 'spring-aop','spring-jdbc', 'spring-web'].each {
        compile "org.springframework:$it:${springframeworkVersion}"

I am almost sure that kind of example is not available through Gradle’s documentation.
Correct me if I am wrong.

Thanks a lot!

This is just a Groovy trick to make the build script a bit more concise, there is nothing Gradle specific here.

The thing is, however, it’s often not obvious to new Gradle users that Gradle scripts just contain Groovy code. You could say this about the entire build script, but the dependencies block is one area where many build scripts could take advantage of this. It would be good for the user guide to occasionally mention where raw Groovy code is commonly useful.

An excellent trick!.. thanks again!

Hello David

I am agree.