我正在尝试将我的maven项目迁移到gradle。我为变量springVersion.中的所有项目指定了spring版本但是,由于某种原因,在一个特定的依赖项org.springframework:spring-web:springVersion.上构建失败。当我直接键入版本时,org.springframework:spring-web:3.1.2.RELEASE会编译所有内容。这是我的build.gradle文件:
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'
}
}错误消息:
* 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在执行测试时,org.Spring框架:spring:3.1.2.RELEASE也是如此。
是什么引起了他的问题,如何解决?
发布于 2012-09-23 14:51:08
字面上说,您正在使用springVersion作为版本。声明依赖项的正确方法是:
// notice the double quotes and dollar sign
compile "org.springframework:spring-context:$springVersion"这是使用Groovy字符串内插,这是Groovy的双引号字符串的一个显著特性。或者,如果您想用Java的方式来实现它:
// could use single-quoted strings here
compile("org.springframework:spring-context:" + springVersion)我不推荐后者,但希望这有助于解释为什么您的代码不能工作。
发布于 2014-12-18 12:45:35
也可以通过dependencies中的变量定义lib版本,如下所示:
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'
}
}https://stackoverflow.com/questions/12551812
复制相似问题