在根项目中找不到任务 'jacoocoTestReport'

Task 'jacoocoTestReport' not found in root project

我试图通过使用 gradle 和 jacoco 找出我的 java 程序中 JUnit 测试的行覆盖率,但以下命令导致失败。

gradle test jacoocoTestReport

命令打印:

FAILURE: Build failed with an exception.

* What went wrong:
Task 'jacoocoTestReport' not found in root project 'ProjectName'. Some candidates are: 'jacocoTestReport'.

* Try:
Run gradle tasks to get a list of available tasks. Run with
    --stacktrace option to get the stack trace. Run with                                           
    --info                                                                          
    or                                                                            
    --debug                                                                         
    option to get more log output.

BUILD FAILED

Total time: 3.389 secs

我的 gradle 项目的 build.gradle:

apply plugin: "jacoco"

apply plugin: 'java'

apply plugin: 'application'

repositories {
   jcenter()
}

dependencies {
   compile 'com.google.guava:guava:20.0'  
   testCompile 'junit:junit:4.12'
}

mainClassName = 'example.Main'

run {
   standardInput = System.in
}

jacocoTestReport {
   reports {
      xml.enabled = true
      html.enabled = true
   }
}

您 运行 一项无效任务(双重 o):

gradle test jacoocoTestReport

而不是:

gradle test jacocoTestReport

你打错了:使用

jacocoTestReport

而不是

jacoocoTestReport

(两个 o)。

使用

gradle tasks

检查定义了哪些任务。