类型的Gradle任务:Test不运行

时间:2015-05-26 19:41:42

标签: gradle

我有一个类型为Test的任务。当我运行任务时,它只是说UP-TO-DATE并且不运行测试,它不执行任务的doLast部分中的操作。你能帮忙吗?

谢谢!

task runIntegrationTests(type: Test) {
    dependsOn compileIntegrationTestJava, processIntegrationTestResources, processTestResources

    testClassesDir = sourceSets.integrationTest.output.classesDir
    classpath = sourceSets.integrationTest.runtimeClasspath

    doLast {
        logger.info("running Cuke tests")
        (new File('build/test-results')).mkdirs()
        javaexec {
            main = "cucumber.api.cli.Main"
            classpath = sourceSets.integrationTest.runtimeClasspath
            args = ['--format', 'pretty',
                    '--format', 'html:build/test-results/cucumber-html',
                    '--format', 'json:build/test-results/cucumber.json',
                    '--tags',   '~@wip',
                    '--format', 'junit:build/test-results/cuke-junit-results.xml',
                    '--glue', 'src/integration/groovy', 'src/integration/resources']
        }
    }
}

:cleanTest UP-TO-DATE
:compileJava UP-TO-DATE
:compileGroovy UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar UP-TO-DATE
:assemble UP-TO-DATE
:compileTestJava UP-TO-DATE
:compileTestGroovy UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:build UP-TO-DATE
:compileIntegrationTestJava UP-TO-DATE
:compileIntegrationTestGroovy UP-TO-DATE
:processIntegrationTestResources UP-TO-DATE
:integrationTestClasses UP-TO-DATE
:runIntegrationTests UP-TO-DATE

BUILD SUCCESSFUL

1 个答案:

答案 0 :(得分:1)

您必须为任务声明输入和输出才能使其运行。如果任务的输入没有改变,则它不会运行。添加例如sourceset到您的输入。请查看gradle文档https://docs.gradle.org/current/userguide/more_about_tasks.html#sec:up_to_date_checks

E.g:

task transform {
    inputs.file srcFile
    outputs.dir destDir
    ...
}