我想在我的Travis构建完成后自动将我的Jacoco测试报告上传到套装。它适用于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
谷歌将我链接到Gradle插件implementation,它显示了这条消息的位置,它告诉我(我认为)找到了Jacoco报告文件,但没有找到coveralls显然需要的源文件。
我尝试了什么
因此,我尝试通过以下所有方式将coveralls任务指向我的源文件:
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"]
}
我还尝试向jacocoTestReport
任务添加sourceSets project.sourceSets.main
。
项目设置
我的最小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'
}
相关问题
在https://github.com/kt3k/coveralls-gradle-plugin/issues/32上基本上也存在同样的问题,但解决方案是设置sourceDirs
和jacocoReportPath
,我已经尝试过了。
sourceDirs += ['src/main/kotlin']
,这听起来很合理,但没有帮助。同样,在第一个链接中,sourceDirs = files(sourceSets.main.kotlin.srcDirs).files.absolutePath
.
project.extensions.coveralls.sourceDirs += project.sourceSets.main.kotlin.srcDirs
,这是我尝试过的。
jacocoTestReport
任务时,在build/reports/jacoco/test/
中生成一个报告。在xml和html中都有。
附注:实际上我想使用Gradle Kotlin DSL,但是因为似乎没有人使用它,所以我问Gradle这个问题。但最后,我希望这个问题也能为Kotlin DSL解决。
发布于 2020-08-10 17:49:36
对于不支持或仅部分支持Kotlin代码库的各种QA产品,有过类似的经验。尝试向几个项目提交支持PR,但都无济于事。
最后,我选择了工作服,并为platform贡献了一个专注于Kotlin的插件
https://github.com/nbaztec/coveralls-jacoco-gradle-plugin
用法
将插件包含在您的build.gradle.kts
中(类似于build.gradle
文件):
plugins {
jacoco
id("com.github.nbaztec.coveralls-jacoco")
}
然后,将环境变量COVERALLS_REPO_TOKEN
设置为Coveralls页面中的令牌。
现在,您可以使用coverallsJacoco
任务来发布覆盖率报告。
有关CI中的更多信息和用法,请参阅https://github.com/nbaztec/coveralls-jacoco-gradle-plugin
发布于 2018-06-20 03:35:08
编辑2020年8月@nbaztec写了一个插件来支持Kotlin,请参阅his answer。
的老答案:
套装不支持Kotlin,例如查看问题中提到的开放isse (在问题中还提到了那里提供的解决方法不起作用):https://github.com/kt3k/coveralls-gradle-plugin/issues/77
解决方案:尝试使用Codecov.io。使用Marketplace将其安装到GitHub并添加到您的.travis.yml
中
after_success:
- bash <(curl -s https://codecov.io/bash)
然后提交并推送,完成!
您可以在https://codecov.io/gh/githubaccountname/reponame上查看结果(在构建完成后
发布于 2021-07-30 17:50:41
没有答案,但以防其他人像我一样在nbaztec中苦苦挣扎,我想给出一个对我有效的替代方案:https://github.com/kt3k/coveralls-gradle-plugin。
除了README.md中的内容之外,我还需要build.gradle中的这个细节:
coveralls {
sourceDirs += ['src/main/kotlin']
jacocoReportPath "${buildDir}/reports/jacoco/report.xml"
}
https://stackoverflow.com/questions/50903389
复制相似问题