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

筅森魡賤 提交于 2019-12-30 05:56:08

问题


When IntelliJ opens a build.gradle file 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.

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

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


回答1:


This is described in Gradle user guide - http://www.gradle.org/docs/current/userguide/idea_plugin.html and http://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.gradle file.



来源:https://stackoverflow.com/questions/24538929/how-do-i-get-intellij-to-resolve-gradle-dependencies-for-custom-source-sets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!