在Docker上运行Gradle integrationTest Task时如何修复':integrationTest NO-SOURCE'

时间:2019-02-05 16:10:35

标签: java docker gradle integration-testing

我有一些用Spring Boot编写的集成测试,想按需运行它们。不是在进行 ./ gradlew构建时,但我想使用 ./ gradlew integrationTest 来运行它们。

我想在Docker容器中运行此 integrationTest 任务

我已经将集成测试代码放在文件夹 src / integrationtest 中,并创建了 integration-test.gradle 文件,如下所示:[我正在使用 Gradle 5.2 ]

sourceSets {
    integrationTest {
        compileClasspath += sourceSets.main.output
        runtimeClasspath += sourceSets.main.output
        resources.srcDir file('src/integrationtest/resources')
    }
}

configurations {
    integrationTestImplementation.extendsFrom testImplementation
    integrationTestRuntimeOnly.extendsFrom testRuntimeOnly
    integrationTestAnnotationProcessor.extendsFrom testAnnotationProcessor
}

idea {
    module {
        testSourceDirs += sourceSets.integrationTest.java.srcDirs
        testResourceDirs += sourceSets.integrationTest.resources.srcDirs
        scopes.TEST.plus += [configurations.integrationTestCompile]
    }
}

task integrationTest(type: Test) {
    description = 'Runs the integration tests.'
    group = 'verification'
    testClassesDirs = sourceSets.integrationTest.output.classesDirs
    classpath = sourceSets.integrationTest.runtimeClasspath
    outputs.upToDateWhen { false }
    shouldRunAfter test
}

check.dependsOn -= integrationTest

并将其应用于我的 build.gradle apply from: 'gradle/integration-test.gradle'

我已经创建了这个docker文件,并将其命名为 Dockerfile.it

FROM openjdk:8u191-jdk-alpine as build
ENV APP_WORKSPACE=/workspace/app/
WORKDIR $APP_WORKSPACE
COPY gradlew .
COPY gradle gradle
COPY build.gradle settings.gradle $APP_WORKSPACE
COPY lombok.config lombok.config
COPY src src
ENV GRADLE_OPTS -Dorg.gradle.daemon=false
ENV AWS_ACCESS_KEY_ID="aws-access-key-id"
ENV AWS_SECRET_ACCESS_KEY="aws-secret-access-key"
ENV AWS_REGION="us-west-2"
ENTRYPOINT ["./gradlew", "integrationTest"]

当我直接在终端上的项目文件夹中运行命令 ./ gradlew integrationTest 时,一切正常,但是当我构建Docker映像并从该映像运行Docker容器时,实际输出为:

Downloading https://services.gradle.org/distributions/gradle-5.2-bin.zip
....................................................................................................................................................................................
Unzipping /root/.gradle/wrapper/dists/gradle-5.2-bin/2di47o96ob6dhysr22jutthm6/gradle-5.2-bin.zip to /root/.gradle/wrapper/dists/gradle-5.2-bin/2di47o96ob6dhysr22jutthm6
Set executable permissions for: /root/.gradle/wrapper/dists/gradle-5.2-bin/2di47o96ob6dhysr22jutthm6/gradle-5.2/bin/gradle
> Task :compileJava
> Task :processResources
> Task :classes
> Task :compileIntegrationTestJava NO-SOURCE
> Task :processIntegrationTestResources NO-SOURCE
> Task :integrationTestClasses UP-TO-DATE
> Task :integrationTest NO-SOURCE

BUILD SUCCESSFUL in 3m 54s
2 actionable tasks: 2 executed

这些是我的问题:

Task :compileIntegrationTestJava NO-SOURCE  
Task :processIntegrationTestResources NO-SOURCE  
Task :integrationTestClasses UP-TO-DATE  
Task :integrationTest NO-SOURCE

我缺少什么或做错了什么?

1 个答案:

答案 0 :(得分:0)

经过更多调查,我发现我做错了一件事情,那就是源文件文件夹的名称,我将其命名为 integrationtest 而不是 integrationTest 为使 integration-test.gradle 文件中的配置正常工作!

enter image description here