带有gradle和kotlin的jacoco并未创建jacoco.exec文件



我已经设置了一个基本的kotlin项目(空类,一个测试文件),并尝试使用gradle插件与gradle设置jacoco:https://docs.gradle.org/current/userguide/jacoco_plugin.html

当我运行测试时,一个测试会通过,但是没有jacoco.exec文件创建。我想念什么?我认为这些课程永远不会得到仪器,但似乎找不到有关如何设置build.jacoco的太多信息。还是可以通过Kotlin创建的仪器类文件?

group 'com.ronnev.filewatcher'
version '0.1'
buildscript {
    ext.kotlin_version = '1.1.61'
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.2'
    }
}
apply plugin: 'kotlin'
apply plugin: 'org.junit.platform.gradle.plugin'
apply plugin: 'jacoco'
repositories {
    mavenCentral()
    jcenter()
}
dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
    testCompile 'org.junit.jupiter:junit-jupiter-api:5.0.2'
    testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.0.2'
}
jacoco {
    toolVersion = "0.7.9"
    reportsDir = file("$buildDir/jacoco/")
}
jacocoTestReport {
    classDirectories = files("${buildDir}/classes")
    reports {
        xml.enabled true
        csv.enabled false
        html.destination file("${buildDir}/jacoco/jacocoHtml")
    }
}
test {
    jacoco {
        append = false
        destinationFile = file("$buildDir/jacoco/jacocoTest.exec")
    }
}

当我运行gradle测试时,我希望创建一个构建/jacoco/jacoco.exec文件,但不是。

vextorspace@vPrecise:~/projects/filewatcher $ gradle clean test
:clean
:compileKotlin
w: /home/vextorspace/projects/filewatcher/src/main/kotlin/com/ronnev/filewatcher/files/DependentFinder.kt: (6, 28): Parameter 'className' is never used
:compileJava UP-TO-DATE
:copyMainKotlinClasses
:processResources UP-TO-DATE
:classes UP-TO-DATE
:compileTestKotlin
:compileTestJava UP-TO-DATE
:copyTestKotlinClasses
:processTestResources
:testClasses
:junitPlatformTest
Test run finished after 71 ms
[         2 containers found      ]
[         0 containers skipped    ]
[         2 containers started    ]
[         0 containers aborted    ]
[         2 containers successful ]
[         0 containers failed     ]
[         1 tests found           ]
[         0 tests skipped         ]
[         1 tests started         ]
[         0 tests aborted         ]
[         1 tests successful      ]
[         0 tests failed          ]
:test SKIPPED
BUILD SUCCESSFUL

当我在构建目录中查看时,没有创建jacoco文件夹:

vextorspace@vPrecise:~/projects/filewatcher $ ls build
classes  kotlin  kotlin-build  kotlin-classes  resources  test-results

任何帮助或提示都将不胜感激!

谢谢!

jacoco尚无法将自己连接到Juint5使用的新任务名称(例如junitPlatformTest)。

您需要"帮助" gradle才能使用task.dependsOn(otherTask)方法调用来创建两个任务之间的连接。

在您的情况下,将其添加到您的构建中。

jacoco {
    // This is the latest version at the time of writing this. Change as you need.
    toolVersion = '0.7.9'
    applyTo junitPlatformTest
}
test.dependsOn junitPlatformTest

最新更新