问题描述
war和jar模块对像Spring,Hibernate等类库都有依赖关系。
我有一个具有多个war模块的多项目构建,依赖于一个jar模块。 ,那些依赖关系在war模块上定义为providedCompile,并在jar上编译。
问题是,当JetGradle更新依赖关系时,所有工件都有错误,因为依赖关系从模块的jar文件都是需要的工件。
我想使用以下解决方案:
- 将库包含在服务器的lib文件夹中,并让Intellij按照提供的方式处理它们。
- 以某种方式将库包含为项目范围库,因此intellij将它们放在即使在更新了gradle依赖关系之后,所有工件也是如此。 >
战争模块中的依赖关系定义为:
providedCompile'org.slf4j:slf4j-log4j12:1.7.5'
providesCompile'org.slf4j:jcl-over-slf4j:1.7.5'
...
compile(project(':jarModule')){transitive = false}
...
jar模块中的依赖被定义为:
...
compile'org.slf4j:slf4j-log4j12:1.7.5'
compile'org.slf4j:jcl-over-slf4j:1.7.5'
...
code>
解决方案我找到的最佳解决方案是从jar中设置可传递的编译依赖项使用Gradle配置文件中的以下代码提供的模块:
apply plugin:'idea'
配置{
提供
provided.extendsFrom(编译)
}
idea {
模块{
scopes.PROVIDED.plus + = configurations.provided
}
}
对于Gradle 2.0+ 修改th最后一点是这样的:
idea {
module {
scopes.PROVIDED.plus + = [configurations.provided]
}
}
此解决方案使用Intellij Gradle插件以及Gradle中的创意任务
我根据这个url上的信息获得了这个解决方案:
我希望这可以帮助别人
I have a multiproject build with multiple war modules that depends on one jar module.
Both war and jar modules have dependencies over libraries like Spring, Hibernate and so on, those dependencies are defined as providedCompile on the war modules and as compile on the jar.
The problem is that when JetGradle updates the dependencies all artifacts have errors, as the dependencies from the jar module are required on the artifacts.
I would like to use any of this solutions:
- Include the libraries on the lib folder of the server and have Intellij treat them as provided.
- Include the libraries as project wide libraries somehow, so intellij puts them on all artifacts even after the gradle dependencies are updated.
On the other hand my approach could be completely wrong from the beginning.
The dependencies in the war modules are defined as:
providedCompile 'org.slf4j:slf4j-log4j12:1.7.5' providedCompile 'org.slf4j:jcl-over-slf4j:1.7.5' ... compile(project(':jarModule')) {transitive = false} ...
The dependencies in the jar module are defined as:
... compile 'org.slf4j:slf4j-log4j12:1.7.5' compile 'org.slf4j:jcl-over-slf4j:1.7.5' ...
解决方案The best solution I found was to set the transitive "compile" dependencies from the jar module as provided using the following code in the Gradle configuration file:
apply plugin: 'idea' configurations { provided provided.extendsFrom(compile) } idea { module { scopes.PROVIDED.plus += configurations.provided } }
For Gradle 2.0+ modify the last bit to be like this:
idea { module { scopes.PROVIDED.plus += [configurations.provided] } }
This solution works using the Intellij Gradle plugin and also the idea task in Gradle
I got this solution working based on the info on this urls:https://github.com/Netflix/RxJava/pull/145http://www.gradle.org/docs/current/dsl/org.gradle.plugins.ide.idea.model.IdeaModule.html
I hope this helps someone else
这篇关于使用Gradle(JetGradle)和Intellij Idea 13提供依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-06 22:55