使用Gradle(JetGradle)和Intellij Idea 13提供依赖关系

Adr*_*pez 11 intellij-idea gradle

我有一个多项目构建,其中包含多个依赖于一个jar模块的war模块.

war和jar模块都依赖于Spring,Hibernate等库,这些依赖项在war模块上定义为provideCompile,在jar上定义为compile.

问题是当JetGradle更新依赖关系时,所有工件都有错误,因为工件需要jar模块的依赖关系.

我想使用以下任何一种解决方案:

  1. 将库包含在服务器的lib文件夹中,让Intellij按照提供的方式处理它们.
  2. 以某种方式将库包含在项目范围库中,因此即使在更新了gradle依赖项之后,intellij也会将它们放在所有工件上.

另一方面,从一开始我的方法就完全错了.

war模块中的依赖关系定义为:

providedCompile 'org.slf4j:slf4j-log4j12:1.7.5'
providedCompile 'org.slf4j:jcl-over-slf4j:1.7.5'
...
compile(project(':jarModule')) {transitive = false}
...
Run Code Online (Sandbox Code Playgroud)

jar模块中的依赖项定义为:

...
compile 'org.slf4j:slf4j-log4j12:1.7.5'
compile 'org.slf4j:jcl-over-slf4j:1.7.5'
...
Run Code Online (Sandbox Code Playgroud)

Adr*_*pez 22

我发现的最佳解决方案是使用Gradle配置文件中的以下代码从jar模块设置传递"编译"依赖项:

apply plugin: 'idea'

configurations {
    provided
    provided.extendsFrom(compile)
}

idea {
    module {
        scopes.PROVIDED.plus += configurations.provided
    }
}
Run Code Online (Sandbox Code Playgroud)

对于Gradle 2.0+,修改最后一位如下:

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

此解决方案使用Intellij Gradle插件以及Gradle中的构思任务

我根据这个网址上的信息得到了这个解决方案:https : //github.com/Netflix/RxJava/pull/145 http://www.gradle.org/docs/current/dsl/org.gradle.plugins. ide.idea.model.IdeaModule.html

我希望这有助于其他人

  • 使用Gradle 2.0或更高版本时,它必须是`scopes.PROVIDED.plus + = [configurations.provided]`.请参阅http://forums.gradle.org/gradle/topics/gradle_2_0_idea_plugin_adding_a_custom_configuration_to_scope_throws_classcastexception (2认同)