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'
rootproject / 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'
}
}
rootproject / module1 / build.gradle:
configurations {
testArtifacts.extendsFrom testRuntime
}
task testJar(type: Jar) {
classifier "test"
from sourceSets.test.output
}
artifacts {
testArtifacts testJar
}
rootproject / module2 / build.gradle
dependencies {
testCompile project (path: ':module1', configuration: 'testArtifacts')
}
使用IntelliJ的gradle向导导入rootproject后,一切都会按预期进行。
更新: