JaCoCo gradle插件忽略版本



Gradle版本:6.1.1

Android Gradle插件:4.0.0

当试图运行我的jacoco报道时,它似乎没有考虑到版本。当我看到HTML报告时;与JaCoCo一起创建0.7.9.201702052155〃;尽管我的设置中有CCD_ 1。该报告也没有我预计在0.8.3中与Kotlin有关的修复,作为对这不起作用的二次确认。

apply plugin: 'jacoco'
jacoco {
toolVersion = "0.8.5"
reportsDir = file("$buildDir/reports")
}
tasks.withType(Test) {
jacoco.includeNoLocationClasses = true
jacoco.excludes = ['jdk.internal.*']
}
project.afterEvaluate {
(android.hasProperty('applicationVariants')
? android.'applicationVariants'
: android.'libraryVariants').all { variant ->
def variantName = variant.name
def unitTestTask = "test${variantName.capitalize()}UnitTest"
def uiTestCoverageTask = "create${variantName.capitalize()}CoverageReport"
tasks.create(name: "${unitTestTask}Coverage", type: JacocoReport, dependsOn: [
"$unitTestTask",
"$uiTestCoverageTask"
]) {
group = "Reporting"
description = "Generate Jacoco coverage reports for the ${variantName.capitalize()} build"
reports {
html.enabled = true
xml.enabled = true
csv.enabled = false
}
def fileFilter = [
'**/R.class',
'**/R$*.class',
'**/BuildConfig.*',
'**/Manifest*.*',
'**/*Test*.*',
'**/com/example/databinding/*',
'**/com/example/generated/callback/*',
'**/android/databinding/*',
'**/androidx/databinding/*',
'**/di/module/*',
'**/*MapperImpl*.*',
'**/*$ViewInjector*.*',
'**/*$ViewBinder*.*',
'**/BuildConfig.*',
'**/*Component*.*',
'**/*BR*.*',
'**/Manifest*.*',
'**/*$Lambda$*.*',
'**/*Companion*.*',
'**/*Module.*',
'**/*Dagger*.*',
'**/*MembersInjector*.*',
'**/*_Factory*.*',
'**/*_Provide*Factory*.*',
'**/*Extensions*.*',
'**/*$Result.*', /* filtering `sealed` and `data` classes */
'**/*$Result$*.*'/* filtering `sealed` and `data` classes */
]
classDirectories.setFrom(files([
fileTree(dir: "${buildDir}/tmp/kotlin-classes/${variantName}", excludes: fileFilter)
]))
def coverageSourceDirs = [
"$project.rootDir/app/src/main/java",
"$project.projectDir/src/${variantName}/java"
]
additionalSourceDirs.setFrom(files(coverageSourceDirs))
sourceDirectories.setFrom(files(coverageSourceDirs))
def uiTestsData = fileTree(dir: "${buildDir}/outputs/code_coverage/${variantName}AndroidTest/connected/", includes: ["**/*.ec"])
executionData(files([
"$project.buildDir/jacoco/${unitTestTask}.exec",
uiTestsData
]))
}
}
}

正如@Bilgehan KALKAN在这里所说,从Gradle 7开始,这似乎已经解决了。

android {
//Other configurations...
testCoverage.jacocoVersion = "0.8.7"
}

对于较低渐变版本,请尝试将其添加到Project gradle文件中。

subprojects {
configurations.all {
resolutionStrategy {
eachDependency { details ->
if ('org.jacoco' == details.requested.group) {
details.useVersion "0.8.6"
}
}
}
}
}

您不需要覆盖@LethalMaus答案中提到的版本。您只需要将android下的jacoco版本指定为testCoverage.jacocoVersion,@Alexy Nikitin上的jacoco.version方法已被弃用,取而代之的是testCoverage.jacocoVersion.

如果您没有指定任何版本,它将使用JacoboOptions类下的DEFAULT_VERSION。这是适用于Android Gradle插件7.0.2版本的"0.8.3"

您也应该在android gradle插件中声明jacoco版本:

android {
jacoco {
version "<your jacoco version>"
}
}

相关内容

  • 没有找到相关文章

最新更新