gpt4 book ai didi

gradle - 如何使用 Gradle Kotlin DSL 设置 codecov?

转载 作者:行者123 更新时间:2023-12-02 13:08:56 24 4
gpt4 key购买 nike

我已阅读codecov/example-gradle我不确定如何将其转换为 Kotlin DSL。

我的.travis.yml:

language: java
jdk:
- openjdk11
before_install:
- chmod +x gradlew
- chmod +x gradle/wrapper/gradle-wrapper.jar
script:
- ./gradlew test
- ./gradlew codeCoverageReport
after_success:
- bash <(curl -s https://codecov.io/bash)

我的build.gradle.kts:

import org.jetbrains.kotlin.gradle.plugin.KotlinPluginWrapper
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm") version "1.2.71"
jacoco
maven
}

repositories {
mavenCentral()
}

dependencies {
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.3.1")
}

tasks {
"test"(Test::class) {
useJUnitPlatform()
}

// Task with name 'codeCoverageReport' not found in root project ''.
"codeCoverageReport"(JacocoReport::class) {
executionData(fileTree(project.rootDir.absolutePath).include("**/build/jacoco/*.exec"))

subprojects.onEach {
sourceSets(it.sourceSets.main)
}

reports {
xml.isEnabled = true
xml.destination = File("$buildDir/reports/jacoco/report.xml")
html.isEnabled = false
csv.isEnabled = false
}

dependsOn("test")
}
}

最佳答案

这是使用 gradle kotlin dsl 的 codecov 的最小工作示例:

.travis.yml:

language: java
jdk:
- openjdk11
before_install:
- chmod +x gradlew
- chmod +x gradle/wrapper/gradle-wrapper.jar
script:
- ./gradlew test build
- ./gradlew codeCoverageReport
after_success:
- bash <(curl -s https://codecov.io/bash)

build.gradle.kts:

import org.jetbrains.kotlin.gradle.plugin.KotlinPluginWrapper
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm") version "1.2.71"
jacoco
java
}

val junit5Version = "5.3.1"
val kotlinVersion = plugins.getPlugin(KotlinPluginWrapper::class.java).kotlinPluginVersion

// This might not be needed in the future, but as of present the default version bundled with the latest version of gradle does not work with Java 11
jacoco {
toolVersion = "0.8.2"
}

repositories {
mavenCentral()
}

dependencies {
testImplementation("org.jetbrains.kotlin:kotlin-test:$kotlinVersion")
testImplementation("org.junit.jupiter:junit-jupiter-engine:$junit5Version")
}

tasks {
"test"(Test::class) {
useJUnitPlatform()
}

val codeCoverageReport by creating(JacocoReport::class) {
executionData(fileTree(project.rootDir.absolutePath).include("**/build/jacoco/*.exec"))

subprojects.onEach {
sourceSets(it.sourceSets["main"])
}

reports {
sourceDirectories = files(sourceSets["main"].allSource.srcDirs)
classDirectories = files(sourceSets["main"].output)
xml.isEnabled = true
xml.destination = File("$buildDir/reports/jacoco/report.xml")
html.isEnabled = false
csv.isEnabled = false
}

dependsOn("test")
}
}

关于gradle - 如何使用 Gradle Kotlin DSL 设置 codecov?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52586697/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com