提问者:小点点

带有gradle和kotlin的Jacoco没有创建Jacoco. exec文件


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

当我运行测试时,一个测试通过了,但是没有创建Jacoco. exec文件。我错过了什么?我假设这些类从未被检测过,但似乎找不到太多关于如何为Jacoco设置build.gradle的信息。或者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 test时,我希望创建一个build/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

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

谢谢你!


共1个答案

匿名用户

Jacoco还不能将自己附加到JUint5使用的新任务名称(例如junitPlatformTest)。

您需要“帮助”Gradle使用task.依赖于(其他任务)方法调用创建两个任务之间的连接。

在您的情况下,将其添加到您的build. gradle可能会起作用:

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