我已经解决了这个,但我仍然很好奇gradle为什么会这样做。
在我的gradle项目中,我有2个gradle项目,一个名为app的配置有ear
插件,另一个名为core,部署在耳朵的lib文件夹中
尝试构建gradle项目时出现以下错误:
FAILURE: Build failed with an exception.
* What went wrong:
Could not resolve all dependencies for configuration ':app:earlib'.
> Could not find org.slf4j:slf4j-api:1.7.5.
Required by:
saturn:app:unspecified > saturn:core:unspecified
> Could not find commons-io:commons-io:2.4.
Required by:
saturn:app:unspecified > saturn:core:unspecified
> Could not find org.slf4j:slf4j-log4j12:1.7.5.
Required by:
saturn:app:unspecified > saturn:core:unspecified
> Could not find log4j:log4j:1.2.17.
Required by:
saturn:app:unspecified > saturn:core:unspecified
我的app build.gradle文件是:
apply plugin: 'ear'
dependencies {
earlib project(":core")
}
我的核心build.gradle是:
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
compile 'org.slf4j:slf4j-api:1.7.5'
runtime 'org.slf4j:slf4j-log4j12:1.7.5'
runtime 'log4j:log4j:1.2.17'
testCompile 'junit:junit:4.11'
}
我能够通过将mavenCentral存储库添加到我的app build.gradle来解决此问题,如下所示:
apply plugin: 'ear'
repositories {
mavenCentral()
}
dependencies {
earlib project(':core')
}
HOWEVER 我仍然很好奇为什么依赖项目需要知道核心项目解析它的依赖关系来自哪个存储库。这个document on dependency management似乎没有很好的解释。
答案 0 :(得分:4)
解析配置时,Gradle(仅)使用与配置在同一项目中声明的存储库。因此,在解决ear项目的earlib
配置时,只考虑ear项目的存储库。这就是为什么在根构建脚本中在subprojects
下声明所有存储库的常见原因之一。