我有一个使用 Gradle 的多模块项目。有一个模块,Data,我有 Neo4J 的依赖项。它使用 lucene-core - 下面的版本 3.6.2。
我将此模块用作另一个模块中的依赖项,即我使用 Jena-Text -版本 1.1.2,它使用 lucene-core 版本 4.6.1。现在,我遇到了冲突,所以我运行了 Gradle 的 dependencyInsight 插件,并排除了 oe 模块中 Neo4J 的依赖项,因为我在那里不需要它们。该代码在 lucene 版本 4.6.1 中使用 gradle 编译良好。
问题是,每当我尝试在 oe 模块中编码时,我都会从 lucence 3.6.2 获得自动完成建议,但是当 Gradle 最终编译它时,它会在 corect 版本(4.6)中执行此操作。 1.
例如,我想在 Lucene 中编写自己的分析器。编写分析器的方式已从版本 3.6 更改为 4.6。现在,如果我的 IDE 不断告诉我,我正在基于一个我最终不会使用的 jar 编写错误的代码,那么编码就变得很困难。 IntelliJ Idea 13 Enterprise Edition 和 Eclipse Luna 中都发生了这种情况。
这就是我排除它们的方式。
compile(project(":data")){
exclude group:'org.springframework.data', module: 'spring-data-neo4j-rest'
exclude group:'org.springframework.data', module: 'spring-data-neo4j'
}
这是在我的 oe 模块中运行 lucene-core 的 depedencyInsight 的结果。
/oe$ gradle -q dependencyInsight --configuration compile --dependency lucene-core
org.apache.lucene:lucene-core:4.6.1
+--- compile
+--- org.apache.jena:jena-text:1.1.2
| \--- compile
+--- org.apache.lucene:lucene-analyzers-common:4.6.1
| +--- compile
| \--- org.apache.jena:jena-text:1.1.2 (*)
+--- org.apache.lucene:lucene-queries:4.6.1
| \--- org.apache.lucene:lucene-queryparser:4.6.1
| \--- org.apache.jena:jena-text:1.1.2 (*)
+--- org.apache.lucene:lucene-queryparser:4.6.1 (*)
\--- org.apache.lucene:lucene-sandbox:4.6.1
\--- org.apache.lucene:lucene-queryparser:4.6.1 (*)
(*) - dependencies omitted (listed previously)
最佳答案
在 intellij
中,您可以通过单击项目结构
中模块的依赖项
选项卡上的向上/向下箭头来确定其使用哪个 jar 的优先级>。不太理想,但应该解决代码完成问题。
关于eclipse - 编译过程中的不同 jar 版本 - Gradle 项目(IntelliJ 和 Eclipse 中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32709399/