我有一个带有 gradle 构建文件的 IntelliJ 项目,其中包括来自 Maven 中央存储库的多个项目。 Geb 就是这样一种依赖项。
当我浏览我的类(class)时,我有时会遇到一个看起来很有趣的 Geb 类(class)。我选择“前往申报”并得到一个悲伤的“找不到要前往的申报”。
显然这是因为 IntelliJ 没有加载 Geb 源文件。但是,在我的项目中不包含 Geb 作为源的情况下,如何让它做到这一点呢?我不希望 Geb 从源代码编译到我的项目中,因为我已经将它作为依赖项包含在我的 gradle 构建文件中。
gradle 脚本的相关部分:
apply plugin: 'groovy'
apply plugin: 'idea'
dependencies {
// need to depend on geb-spock
testCompile "org.gebish:geb-spock:0.13.1"
testCompile "org.spockframework:spock-core:1.0-groovy-2.4"
testCompile "org.apache.commons:commons-lang3:3.4"
testCompile "io.github.bonigarcia:webdrivermanager:1.5.0"
testRuntime "org.seleniumhq.selenium:selenium-support:2.53.1"
}
idea {
module {
downloadJavadoc = true // defaults to false
downloadSources = true
}
}
最佳答案
这是一个完整的构建脚本,可以下载所有源代码的依赖项:
apply plugin: 'java'
apply plugin: 'idea'
idea {
module {
downloadJavadoc = true // defaults to false
downloadSources = true
}
}
repositories {
mavenCentral()
}
dependencies {
// need to depend on geb-spock
testCompile "org.gebish:geb-spock:0.13.1"
testCompile "org.spockframework:spock-core:1.0-groovy-2.4"
testCompile "org.apache.commons:commons-lang3:3.4"
testCompile "io.github.bonigarcia:webdrivermanager:1.5.0"
testRuntime "org.seleniumhq.selenium:selenium-support:2.53.1"
}
task wrapper(type: Wrapper) {
gradleVersion = '3.3'
}
依赖项显示在列表中:
而且我可以浏览源代码,您可以看到那里的注释:
一种可能的解释可能是您的存储库列表中有一个存储库,例如 mavenLocal 或缓存 Artifactory,它没有源依赖项。
存储库的顺序很重要,所以如果 mavenLocal 是第一个并且那里的源不可用,我相信它们不会被下载。一个可能的解决方法是从 mavenLocal 中删除依赖项并重新下载它,更改依赖项的顺序,或者如果它是父脚本,则在添加存储库时免除您的子项目:
configure(allprojects - project(':my-subproj')) {
repositories {
...
}
}
我不认为有任何方法可以防止子项目的构建脚本发生这种情况。它必须在父级中完成。
关于intellij-idea - 如何将依赖源添加到 IntelliJ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42079908/