有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

测试IntelliJ无法解决gradle java跨模块测试依赖关系

IntelliJ 2016.1 格拉德尔2.1

在命令行中使用直线渐变,一切都很好

项目结构:

build.gradle
\module1\build.gradle
\module1\src\test\......
\module2\build.gradle
\module2\src\test\......

模块2使用模块1中的测试类。IntelliJ显示“无法解析符号”错误。IntelliJ中的修复操作是“添加对模块的依赖”,它什么也不做

如果我手动编辑module1_文本。iml文件和添加

<orderEntry type="module" module-name="module1_test" production-on-test="" />

然后它会起一点作用

IntelliJ是否因为某种原因无法编辑iml文件?还是gradle中的某些配置不正确

我的身材。gradle以以下方式包含测试代码:

testCompile project (path: ':modules:module1')

共 (1) 个答案

  1. # 1 楼答案

    通过遵循this方法,我能够创建对另一个项目的测试类的依赖关系

    根项目/设置。格雷德尔:

    rootProject.name = 'rootproject'
    include 'module1'
    include 'module2'
    

    根项目/构建。格雷德尔:

    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。格雷德尔:

    configurations {
        testArtifacts.extendsFrom testRuntime
    }
    task testJar(type: Jar) {
        classifier "test"
        from sourceSets.test.output
    }
    artifacts {
        testArtifacts testJar
    }
    

    rootproject/module2/build。格拉德尔

    dependencies {
        testCompile project (path: ':module1', configuration: 'testArtifacts')
    }
    

    在使用IntelliJ的gradle向导导入rootproject后,一切正常


    更新:

    • 添加了rootproject的设置。格雷德尔锉刀