简体   繁体   English

JUnit5 Gradle插件会覆盖默认的构建任务

[英]JUnit5 Gradle plugin overrides the default build task

I'm using the JUnit 5 Gradle plugin as explained here: http://junit.org/junit5/docs/current/user-guide/#running-tests-build-gradle 我正在使用JUnit 5 Gradle插件,如下所述: http//junit.org/junit5/docs/current/user-guide/#running-tests-build-gradle

I added the following parts to my gradle.build file: 我将以下部分添加到我的gradle.build文件中:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.3'
    }
}

plugins {
    id 'java'
    id 'application'
    // ... some others...
}

apply plugin: 'org.junit.platform.gradle.plugin'

dependencies {
    testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.0.3'
    testRuntime group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.0.3'
}

With the above, when I use the gradle build task - I have the following output: 有了上面的内容,当我使用gradle build任务时 - 我有以下输出:

Executing task 'build'...

:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar
:findMainClass
:startScripts UP-TO-DATE
:distTar
:distZip
:bootRepackage
:assemble
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:junitPlatformTest UP-TO-DATE
:test SKIPPED
:check UP-TO-DATE
:build

BUILD SUCCESSFUL

Since this includes junitPlatformTest I assume that the plugin overrides the regular build task. 由于这包括junitPlatformTest我假设插件会覆盖常规build任务。 I would like to know if there's any way to avoid this behavior. 我想知道是否有任何方法可以避免这种行为。

The plugin does not override the build task. 该插件不会覆盖build任务。 It adds a dependency from the test task to the junitPlatformTest task and (by default) disables the standard test task (to avoid executing JUnit 4-based tests multiple times). 它添加了从test任务到junitPlatformTest任务的junitPlatformTest项,并且(默认情况下)禁用标准test任务(以避免多次执行基于JUnit 4的测试)。

build depends on check and assemble , check depends on test (see Gradle User Manual ). build取决于checkassemblecheck取决于test (请参阅Gradle用户手册 )。 Thus, when you execute build , junitPlatformTest will be executed as in your example. 因此,当您执行build ,将在您的示例中执行junitPlatformTest

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM