Gradle解决多项目的依赖项中的ext属性

时间:2015-05-20 11:43:59

标签: gradle build.gradle multi-project

我有以下多项目结构(仅显示重要部分):

- project
    - build.gradle (file) 
    - settings.gradle (file)
    + module1 (dir)
    + module2 (dir)

的build.gradle

ext {
    groovyMajorVersion = 2.4
    groovyMinorVersion = 3
}
subprojects {
    dependencies {
        testCompile 'org.codehaus.groovy:groovy-all:${groovyMajorVersion}.${groovyMinorVersion}'
        testCompile 'org.spockframework:spock-core:1.0-groovy-${groovyMajorVersion}'
    }
}

settings.gradle

include 'module1', 'module2'

当我从module1运行gradle dependencies时,出现以下错误:

testCompile - Compile classpath for source set 'test'.
+--- org.codehaus.groovy:groovy-all:${groovyMajorVersion}.${groovyMinorVersion} FAILED
\--- org.spockframework:spock-core:1.0-groovy-${groovyMajorVersion} FAILED

1 个答案:

答案 0 :(得分:2)

这是因为在依赖项块内部,您使用撇号(')而不是引号(")包装依赖项,因此依赖项内的参数无法解析。要修复,只需用引号替换撇号,即:

    testCompile "org.codehaus.groovy:groovy-all:${groovyMajorVersion}.${groovyMinorVersion}"
    testCompile "org.spockframework:spock-core:1.0-groovy-${groovyMajorVersion}"