I am trying to migrate my maven project to gradle. I specify spring version for all the project in variable springVersion. But from some reason build fails on one particular dependency org.springframework:spring-web:springVersion. When I type the version directly org.springframework:spring-web:3.1.2.RELEASE everything compiles. Here is my build.gradle file:
subprojects {
apply plugin: 'java'
apply plugin: 'eclipse-wtp'
ext {
springVersion = "3.1.2.RELEASE"
}
repositories {
mavenCentral()
}
dependencies {
compile 'org.springframework:spring-context:springVersion'
compile 'org.springframework:spring-web:springVersion'
compile 'org.springframework:spring-core:springVersion'
compile 'org.springframework:spring-beans:springVersion'
testCompile 'org.springframework:spring-test:3.1.2.RELEASE'
testCompile 'org.slf4j:slf4j-log4j12:1.6.6'
testCompile 'junit:junit:4.10'
}
version = '1.0'
jar {
manifest.attributes provider: 'gradle'
}
}
ERROR MESSAGE:
* What went wrong:
Could not resolve all dependencies for configuration ':hi-db:compile'.
> Could not find group:org.springframework, module:spring-web, version:springVersion.
Required by:
hedgehog-investigator-project:hi-db:1.0
The same is with org.springframework:spring-test:3.1.2.RELEASE when performing tests.
Whats causing he problem and how to solve it?
You are using springVersion
as the version, literally. The correct way to declare the dependencies is:
// notice the double quotes and dollar sign
compile "org.springframework:spring-context:$springVersion"
This is using Groovy String interpolation, a distinguishing feature of Groovy's double-quoted strings. Or, if you want to do it the Java way:
// could use single-quoted strings here
compile("org.springframework:spring-context:" + springVersion)
I don't recommend the latter, but it hopefully helps to explain why your code doesn't work.
Or you can define lib version via variable in dependencies
like this:
dependencies {
def tomcatVersion = '7.0.57'
tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}",
"org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}"
tomcat("org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}") {
exclude group: 'org.eclipse.jdt.core.compiler', module: 'ecj'
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With