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

标签 java intellij-idea gradle dependency-management

当 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

最佳答案

这在 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 文件。

关于java - 如何让 IntelliJ 解决自定义源集的 Gradle 依赖项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24538929/

相关文章:

java - IntelliJ 中代码的自定义格式

java.lang.NoSuchMethodError : org. hibernate.engine.spi.SessionFactoryImplementor.getProperties()Ljava/util/属性

java - Eclipse + Velocity = HTTP 状态 500

java - 将文档类型插入 XML 文档 (Java/SAX)

java - 从另一个类获取字符串正在传递 null

javascript - 必需的字符串参数 'text' 不存在

ruby - IntelliJ + Ruby 插件与 RubyMine 之间的最大区别是什么?

user-interface - Gradle GUI设置的位置

java - libGDX 设置允许我使用在 Android 中崩溃的 Java 8

ios - 构建 Kotlin MPP iOS 应用程序时出现 XCode 错误