nebula-test 无法在 copyResources 的类路径中找到资源目录

nebula-test fails to find resources dir in classpath for copyResources

我正在使用 nebula-test 为我的第一个 Gradle 插件编写集成测试。

我现在正在进行一项测试,需要将我的 "resources" 中的一个或多个文件复制到临时项目目录中。 "copyResources()" 调用失败,因为它表示 "from" 目录不在类路径中。

具体来说,它失败了:

java.lang.RuntimeException: Could not find classpath resource: src/integTest/resources
at nebula.test.IntegrationSpec.copyResources(IntegrationSpec.groovy:189)
at com.att.opnfv.yang.gradle.YangPluginIntegSpec.process Yang module with simple type reference and imported file for type(YangPluginIntegSpec.groovy:227)

这是我的 "build.gradle" 文件的相关部分:

    buildscript {
        repositories {
            jcenter()
            mavenCentral()
        }
    }

    apply plugin: 'groovy'
    apply plugin: 'java-gradle-plugin'
    apply plugin: 'maven'

    repositories {
        mavenCentral()
        jcenter()
    }

    dependencies {
        compile "org.codehaus.groovy:groovy-all:2.3.9"
        compile gradleApi()
        compile "commons-io:commons-io:2.4"

        testCompile("org.spockframework:spock-core:1.0-groovy-2.3") {
            exclude group: "org.codehaus.groovy"
        }
    }

    sourceCompatibility = 1.7

    group = 'com.att.opnfv.yang'
    version = '1.0.0-SNAPSHOT'

    tasks.withType(Test) {
            testLogging {
                    exceptionFormat "full"
            }
    }

    sourceSets {
        integTest {
            groovy.srcDir file("src/integTest/groovy")
            resources.srcDir file("src/integTest/resources")
            runtimeClasspath = output + compileClasspath // I thought this would do it
        }
    }

    dependencies {
        integTestCompile sourceSets.main.output
        integTestCompile configurations.testCompile
        integTestCompile sourceSets.test.output
        integTestRuntime configurations.testRuntime

        testCompile( 'com.netflix.nebula:nebula-test:2.2.1' ) {
            exclude module: 'groovy-all'
        }
    }

    task integTest(type: Test) {
        testClassesDir  = sourceSets.integTest.output.classesDir
        classpath     = sourceSets.integTest.runtimeClasspath
        outputs.upToDateWhen { false }
    }

    check.dependsOn -= integTest

这是我的 Spec 方法,它有 "copyResources()" 调用:

def 'process Yang module with simple type reference and imported file for type'() {
    when:
    directory("src/main/yang")
    File yangFile = createFile("src/main/yang/base.yang")
    yangFile << '''
    module base {
        namespace "base";
        prefix base;

        import ietf-inet-types {prefix inet; revision-date "2010-09-24";}

        grouping "group" {
            leaf ip-base {
                type inet:ip-version;
            }
        }
    }
    '''.stripIndent()

    directory("yangImports")

    copyResources("src/integTest/resources", "yangImports") // line 227

    buildFile << applyPlugin(YangPlugin)
    buildFile << """
        configurations {
            yangImports
        }
        dependencies {
            yangImports fileTree(dir: "yangImports", include: "*.yang")
        }
        yang {
            yangFilesConfiguration "yangImports"
            inspectDependencies     true
            yangFilesRootDir        'src/main/yang'
            generator {
                generatorClassName  = 'com.att.opnfv.yang.generator.MockCodeGenerator'
                outputDir           = 'build/gen'
            }
        }
    """.stripIndent()

    ExecutionResult result = runTasksWithFailure('build')

    then:
    !result.wasUpToDate("yangGenerate")
    result.standardError.contains("Imported module ietf-inet-types not found")
}

我错过了什么?

更新:

我对配置类路径和 "copyResources" 中引用的路径之间的关系感到困惑。我创建了 "src/integTest/resources/yang",将一个文件复制到那个新文件夹中,然后将引用更改为:

copyResources("yang", "yangImports")

这很有效,或者至少它克服了那个问题,这样我就可以克服下一个障碍,但这不是 Gradle/nebula-test 问题。

我的错误是在 "copyResources" 调用中引用了 "src/integTest/resources"。该文件夹已经在类路径中。我需要参考的是 "src/integTest/resources" 的文件夹 INSIDE。一旦我这样做了,它就很好用了。