IntelliJ 2016.1 Gradle 2.1
使用直接 gradle 在命令行上一切正常。
项目结构:
build.gradle
\module1\build.gradle
\module1\src\test\......
\module2\build.gradle
\module2\src\test\......
模块 2 使用模块 1 中的测试类。IntelliJ 显示“无法解析符号”错误。 IntelliJ 中的修复操作是“添加对模块的依赖性”,它什么都不做。
如果我手动编辑module1_text.iml文件并添加
<orderEntry type="module" module-name="module1_test" production-on-test="" />
然后它工作了一点。
IntelliJ 是否由于某种原因无法编辑 iml 文件?还是 gradle 中配置不正确?
我的 build.gradle 以下列方式包含测试代码:
testCompile project (path: ':modules:module1')
最佳答案
我能够通过遵循 this 创建对另一个项目的测试类的依赖方法。
rootproject/settings.gradle:
rootProject.name = 'rootproject'
include 'module1'
include 'module2'
根项目/build.gradle:
task wrapper(type: Wrapper) { gradleVersion = "2.14" }
allprojects {
repositories {
mavenCentral()
}
}
subprojects {
apply plugin: 'java'
apply plugin: 'idea'
sourceCompatibility = 1.8
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
}
}
根项目/module1/build.gradle:
configurations {
testArtifacts.extendsFrom testRuntime
}
task testJar(type: Jar) {
classifier "test"
from sourceSets.test.output
}
artifacts {
testArtifacts testJar
}
根项目/module2/build.gradle
dependencies {
testCompile project (path: ':module1', configuration: 'testArtifacts')
}
在使用 IntelliJ 的 gradle 向导导入根项目后,一切都按预期进行。
更新:
- 添加根项目的settings.gradle文件
关于java - IntelliJ 无法解析 gradle java 跨模块测试依赖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37889736/