【问题标题】:How do I get IntelliJ to resolve Gradle dependencies for custom source sets?如何让 IntelliJ 解决自定义源集的 Gradle 依赖项?
【发布时间】:2014-08-23 16:55:46
【问题描述】:

当 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')
}

详细信息: IntelliJ 13.1.2,Gradle 1.11

【问题讨论】:

    标签: java intellij-idea gradle dependency-management


    【解决方案1】:

    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 ]
      }
    }
    

    到您的build.gradle 文件。

    【讨论】:

    • 感谢您添加文档链接!
    • 从 gradle 3.1 开始,我有 [configurations.testCompile]。不过感谢您的回答!
    猜你喜欢
    • 2013-09-25
    • 2017-02-15
    • 1970-01-01
    • 2016-06-19
    • 1970-01-01
    • 2014-02-07
    • 1970-01-01
    • 1970-01-01
    • 2018-03-06
    相关资源
    最近更新 更多