gradle 2.8子项目依赖项-找不到compile()



我有一个根gradle项目和10个子项目。我希望只在根项目中指定5个依赖项,而不将它们复制粘贴到所有10个模块。如果我写:

subprojects{
  dependencies{
    compile 'org.codehaus.groovy:groovy-all:2.3.11'
    compile 'org.springframework:spring-core:4.1.2.RELEASE'
    compile 'org.springframework:spring-context:4.1.2.RELEASE'
  }
}

它告诉我CCD_ 1方法还没有找到。如何让它工作,所以我应该只在一个地方指定deps?

您是否已将java插件应用于:

allprojects {
   apply plugin: 'java'
}

或:

subprojects {
   apply plugin: 'java'
}

请记住,您还需要添加存储库块。它将是:

repositories {
   mavenCentral()
   jcenter()
}

分级文档参考:8.2。声明您的依赖项

您必须使用dependencies关键字包装编译依赖项,如:

subprojects {
  dependencies {
    compile 'org.codehaus.groovy:groovy-all:2.3.11'
    compile 'org.springframework:spring-core:4.1.2.RELEASE'
    compile 'org.springframework:spring-context:4.1.2.RELEASE'
  }
}

这也适用于仅限root用户的库。

最新更新