如何将Kotlin源的测试报告上传到Coveralls?

问题描述 投票:3回答:1

我想在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

谷歌将我链接到Gradle插件implementation,它显示了它抛出此消息的位置,它告诉我(我认为)找到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"]
}

我也尝试将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'
}

相关问题

PS其实我想使用Gradle Kotlin DSL,但由于似乎没有人使用它,我问Gradle这个问题。但最后我想要为Kotlin DSL解决这个问题。

gradle kotlin jacoco coveralls gradle-kotlin-dsl
1个回答
2
投票

工作服不支持Kotlin,例如,请参阅问题中提到的这个开放式问题(在问题中也提到了那里提供的解决方法不起作用):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查看结果(构建完成后)

© www.soinside.com 2019 - 2024. All rights reserved.