如何让IntelliJ解决自定义源集的Gradle依赖关系?

Mik*_*der 13 java intellij-idea dependency-management gradle

当IntelliJ打开build.gradle文件时,它将生成一个IntelliJ项目,其中Gradle依赖项已解析并添加到项目范围.这对于"编译"源集和"测试"源集非常有用,但是我无法使其适用于自定义源集.

我希望IntelliJ解析componentTest源集的依赖关系.如何告诉IntelliJ解决这些依赖关系并将其添加到范围?

dependencies {
    // main source set, "compile" scope in IntelliJ
    compile(group: 'com.google.guava', name: 'guava', version: '18.0')

    // test source set, "test" scope in IntelliJ 
    testCompile(group: 'junit', name: 'junit', version: '4.11')

    // my custom source set, not added to any scope in IntelliJ
    componentTestCompile(group: 'org.springframework', name: 'spring', version: '3.0.7')
}
Run Code Online (Sandbox Code Playgroud)

详细信息: IntelliJ 13.1.2,Gradle 1.11

Rad*_*dim 18

Gradle用户指南 - http://www.gradle.org/docs/current/userguide/idea_plugin.htmlhttp://www.gradle.org/docs/current/dsl/org.gradle.plugins中对此进行了描述. ide.idea.model.IdeaModule.html

您需要添加以下内容:

idea {
  module {
    scopes.TEST.plus += [ configurations.componentTestCompile ]
  }
}
Run Code Online (Sandbox Code Playgroud)

到你的build.gradle文件.