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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24538929/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 12:47:53  来源:igfitidea点击:

How do I get IntelliJ to resolve Gradle dependencies for custom source sets?

javaintellij-ideagradledependency-management

提问by Mike Rylander

When IntelliJ opens a build.gradlefile it will generate an IntelliJ project with the Gradle dependencies resolved and added to the project scope. This works great for the "compile" source set and the "test" source set, however I can not get this to work for custom source sets.

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

I want to have IntelliJ resolve the dependencies for my componentTestsource set. How do I tell IntelliJ to resolve these dependencies and add them to scope?

我想让 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')
}

Details:IntelliJ 13.1.2, Gradle 1.11

详细信息:IntelliJ 13.1.2,Gradle 1.11

采纳答案by Radim

This is described in Gradle user guide - http://www.gradle.org/docs/current/userguide/idea_plugin.htmland http://www.gradle.org/docs/current/dsl/org.gradle.plugins.ide.idea.model.IdeaModule.html

这在 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

You will need to add something like:

您将需要添加如下内容:

idea {
  module {
    scopes.TEST.plus += [ configurations.componentTestCompile ]
  }
}

to your build.gradlefile.

到您的build.gradle文件。