gradle - 如何使用 Gradle Kotlin DSL 设置 codecov?
问题描述
我已阅读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")
}
}
推荐阅读
- python-requests - 使用字典的预算程序
- java - 具有2个数组列表的非递归合并排序
- vba - 获取 Dymo 标签的对象名称
- javascript - Uncaught (in promise) TypeError: cannot read property graphics of undefined
- ios - (目标 C)TABLEVIEW 单元格标识符重要吗?
- python-3.x - 如何通过双击运行python代码而不自己激活virtualenv
- strapi - 如何覆盖 Strapi 管理面板端点?
- json - 将记录编组为 JSON 并返回
- authentication - Mifare Desfire EV1:了解认证过程命令
- wordpress - 在 jquery 中添加联系 form7 简码