PHP*_*ate 7 gradle jacoco kotlin coveralls gradle-kotlin-dsl
我想在 Travis 构建完成后自动将我的 Jacoco 测试报告上传到 Coveralls。它适用于 Java,但如何为 Kotlin 配置它?
错误信息
我可以在本地和 Travis 上生成 Jacoco 测试报告,但是当 Travis 尝试提交给工作服时,它会失败并显示消息
> Task :coveralls
No source file found on the project: "kotlin-template-project"
With coverage file: /home/travis/build/myname/myreponame/build/reports/jacoco/test/jacocoTestReport.xml
Run Code Online (Sandbox Code Playgroud)
Google 将我链接到 Gradle 插件实现,它显示了它在哪里抛出此消息,它告诉我(我认为)找到了 Jacoco 报告文件,但没有找到工作人员显然需要的源文件。
我试过的
因此,我尝试通过所有这些方式将工作服任务指向我的源文件:
coveralls {
sourceDirs += allprojects.sourceSets.main.allSource.srcDirs.flatten()
sourceDirs += files(sourceSets.main.kotlin.srcDirs).files.absolutePath
project.extensions.coveralls.sourceDirs += project.sourceSets.main.kotlin.srcDirs
sourceDirs += ['src/main/kotlin']
jacocoReportPath = 'build/reports/jacoco/test/jacocoTestReport.xml'
sourceDirs += ['src/test/kotlin']
sourceDirs += ["${projectDir}/src/main/kotlin"]
}
Run Code Online (Sandbox Code Playgroud)
我也尝试添加sourceSets project.sourceSets.main到jacocoTestReport任务中。
项目设置
我的最小build.gradle文件:
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.2.50'
id 'java' // Required by at least JUnit.
// Test coverage
id 'jacoco'
// Upload jacoco coverage reports to coveralls
id 'com.github.kt3k.coveralls' version '2.8.2'
}
dependencies {
compile 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
// JUnit 5
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.2.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.2.0'
testRuntime 'org.junit.platform:junit-platform-console:1.2.0'
// Kotlintest
testCompile 'io.kotlintest:kotlintest-core:3.1.6'
testCompile 'io.kotlintest:kotlintest-assertions:3.1.6'
testCompile 'io.kotlintest:kotlintest-runner-junit5:3.1.6'
// Spek
testCompile 'org.jetbrains.spek:spek-api:1.1.5'
testRuntime 'org.jetbrains.spek:spek-junit-platform-engine:1.1.5'
}
repositories {
mavenCentral()
mavenLocal()
jcenter()
}
test {
// Enable JUnit 5 (Gradle 4.6+).
useJUnitPlatform()
// Always run tests, even when nothing changed.
dependsOn 'cleanTest'
// Show test results.
testLogging {
events "passed", "skipped", "failed"
}
}
// Test coverage reporting
jacocoTestReport {
// Enable xml for coveralls.
reports {
html.enabled = true
xml.enabled = true
xml.setDestination(file("${buildDir}/reports/jacoco/test/jacocoTestReport.xml"))
}
}
coveralls {
sourceDirs += ['src/main/kotlin']
jacocoReportPath = 'build/reports/jacoco/test/jacocoTestReport.xml'
}
Run Code Online (Sandbox Code Playgroud)
相关问题
sourceDirs并且jacocoReportPath我已经尝试过。sourceDirs += ['src/main/kotlin']听起来合理但不没有帮助。同样,从第一个链接开始,sourceDirs = files(sourceSets.main.kotlin.srcDirs).files.absolutePath.project.extensions.coveralls.sourceDirs += project.sourceSets.main.kotlin.srcDirs我尝试过的。这个问题在CI管线科特林代码覆盖率的措辞相当普遍,但评论指向discuss.kotlinlang.org如果有人节目,以提高关于科特林的Jacoco结果的方式,答案链接到Jacoco摇篮插件,我使用和作品:当我运行jacocoTestReport任务时build/reports/jacoco/test/,会在 xml 和 html 中生成报告。
Kotlin 测试覆盖率问题也很笼统,用一个不必要的复杂构建文件来回答,我从中没有学到任何新东西。
PS实际上我想使用Gradle Kotlin DSL,但是由于似乎没有人使用它,所以我向Gradle提出了这个问题。但最终我希望 Kotlin DSL 也能解决这个问题。
对于各种不支持或仅部分支持 Kotlin 代码库的 QA 产品也有类似的经历。尝试向几个项目提交支持 PR,但无济于事。
最终选择了 Coveralls 并为该平台贡献了一个以 Kotlin 为中心的插件
https://github.com/nbaztec/coveralls-jacoco-gradle-plugin
将插件包含在您的文件中build.gradle.kts(与文件类似build.gradle):
plugins {
jacoco
id("com.github.nbaztec.coveralls-jacoco")
}
Run Code Online (Sandbox Code Playgroud)
然后将环境变量设置COVERALLS_REPO_TOKEN为 Coveralls 页面中的令牌。
现在您可以使用该coverallsJacoco任务来发布覆盖率报告。
有关 CI 的更多信息和用法,请参阅 https://github.com/nbaztec/coveralls-jacoco-gradle-plugin
| 归档时间: |
|
| 查看次数: |
858 次 |
| 最近记录: |