dr_pompeii
(Manuel Jordan)
August 13, 2015, 11:31pm
1
Hello
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'
or
'org.springframework:spring-core:2.5',
'org.springframework:spring-aop:2.5',
'org.springframework:spring-mvc: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"
}
}
dr_pompeii
(Manuel Jordan)
August 14, 2015, 9:53pm
3
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}",
"org.slf4j:jcl-over-slf4j:${slf4jVersion}",
"ch.qos.logback:logback-classic:${logbackVersion}"
['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.
David_Karr
(davidmichaelkarr)
August 15, 2015, 3:06am
5
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.
dr_pompeii
(Manuel Jordan)
August 15, 2015, 1:33pm
6
An excellent trick!.. thanks again!