编译期间的不同 jar 版本 - Gradle 项目(在 IntelliJ 和 Eclipse 中)

Different jar versions in during compile - Gradle Project(Both in IntelliJ and Eclipse)

我有一个多模块项目,我正在使用 Gradle。有一个模块,Data,我在其中依赖于 Neo4J。它使用 lucene-core - 下面是 3.6.2 版本。

我将此模块用作另一个模块中的依赖项,oe 我正在使用 Jena-Text -version 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 编写自己的 Analyzer。编写分析器的方式已从 3.6 版更改为 4.6 版。现在编码变得很困难,如果我的 IDE 一直告诉我,我写的代码是错误的,基于我最终不会使用的 jar。这在 IntelliJ Idea 13、企业版和 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 模块中 运行 depedencyInsight for lucene-core 的结果。

/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 中,您可以通过单击 project structure 中模块的 dependencies 选项卡上的 up/down 箭头来确定它使用的 jar 的优先级。不理想,但应该解决代码完成问题。