Naveen Kumar
Naveen Kumar

Reputation: 1432

How to enable code coverage with Kotlin dsl gradle?

When enabling jacoco with gradle kotlin dsl it fails because it looks at build.gradle file instead of build.gradle.kts file.

Here is the error :

##[warning]Unable to append code coverage data: Error: File or folder doesn't exist: /home/vsts/work/1/s/build.gradle
##[warning]Failed to enable code coverage: Unable to append code coverage data: Error: File or folder doesn't exist: /home/vsts/work/1/s/build.gradle

app/build.gradle.kts

plugins {
    jacoco
}

tasks.withType(JacocoReport::class.java).all {
    reports {
        xml.isEnabled = true
        xml.destination = File("$buildDir/reports/jacoco/report.xml")
    }
}

tasks.withType<Test> {
    jacoco {
        toolVersion = "0.8.3"
        reportsDir = file("$buildDir/reports/jacoco")
    }
    finalizedBy("jacocoTestReport")
}

Azure DevOps task

- task: Gradle@2
  displayName: Gradle Build
  inputs:
      gradleWrapperFile: 'gradlew'
      tasks: ':app:assembleDevDebug :networking:lintDebug :app:lintDevDebug --warning-mode all'
      publishJUnitResults: false
      testResultsFiles: '**/TEST-*.xml'
      javaHomeOption: 'JDKVersion'
      sonarQubeRunAnalysis: false
      codeCoverageToolOption: 'jaCoCo'

Upvotes: 1

Views: 2031

Answers (1)

Godin
Godin

Reputation: 10564

Messages

##[warning]Unable to append code coverage data: Error: File or folder doesn't exist: /home/vsts/work/1/s/build.gradle
##[warning]Failed to enable code coverage: Unable to append code coverage data: Error: File or folder doesn't exist: /home/vsts/work/1/s/build.gradle

are produced by AzureDevOps Gradle Task due to usage of option

codeCoverageToolOption: 'jaCoCo'

in your configuration of this task, because implementation of AzureDevOps Gradle Task contains hardcoded value build.gradle:

quoting comment from the above bug ticket

The way for you to use code coverage would be to enable it in your build config files and publish them using another task - PublishCodeCoverageResults

Upvotes: 2

Related Questions