scoverage / scalac-scoverage-plugin

Scoverage Scala Code Coverage Core Libs
https://github.com/scoverage
Apache License 2.0
423 stars 126 forks source link

Error during reading report 'xxx/target/cobertura.xmlObject reference not set to an instance of an object #509

Closed Schuits closed 1 year ago

Schuits commented 1 year ago

Describe the bug

I cannot publish Scoverage reports to SonarQube using PublishCodeCoverageResults@1 in a Azure Devops CI/CD pipeline on a self hosted linux agent..

I'm using Maven,scala version 2.11.12, java and scoverage-maven-plugin. After compiling and running the scala tests, I switch the devops environment to Java 11 and attempt to publish the code coverage results with the following : (full path redacted)

#  - task: PublishCodeCoverageResults@1
     displayName: 'Publish Code Coverage'
     inputs:
       codeCoverageTool: 'Cobertura'
       summaryFileLocation: '$(Build.SourcesDirectory)/xx/target/cobertura.xml'
       reportDirectory: '$(Build.SourcesDirectory)/xx/target/site/scoverage'

I receive the following output


/usr/bin/dotnet /workspace/_tasks/PublishCodeCoverageResults_2a7ebc54-c13e-490e-81a5-d7561ab7cd97/1.200.0/netcoreapp2.0/ReportGenerator.dll -reports:/workspace/58/s/xx/target/cobertura.xml -targetdir:/workspace/_temp/cchtml -reporttypes:HtmlInline_AzurePipelines
2022-10-12T08:12:31: Arguments
2022-10-12T08:12:31:  -reports:/workspace/58/s/xx/target/cobertura.xml
2022-10-12T08:12:31:  -targetdir:/workspace/_temp/cchtml
2022-10-12T08:12:31:  -reporttypes:HtmlInline_AzurePipelines
2022-10-12T08:12:32: Error during reading report '/workspace/58/s/xx/target/cobertura.xml' (Size: 7.3MB): Object reference not set to an instance of an object.
2022-10-12T08:12:32: Writing report file '/workspace/_temp/cchtml/index.html'
2022-10-12T08:12:32: Report generation took 0.9 seconds
##[debug]Exit code 0 received from tool '/usr/bin/dotnet'
##[debug]STDIO streams have closed for tool '/usr/bin/dotnet'
Generated code coverage html report: /workspace/_temp/cchtml
##[debug]Result: true
##[warning]Ignoring coverage report directory with Html content as we are auto-generating Html content
##[debug]Processed: ##vso[task.issue type=warning;]Ignoring coverage report directory with Html content as we are auto-generating Html content
##[debug]Report directory: /workspace/_temp/cchtml
Reading code coverage summary from '/workspace/58/s/xx/target/cobertura.xml'
##[debug]Processed: ##vso[codecoverage.publish codecoveragetool=Cobertura;summaryfile=/workspace/58/s/xx/target/cobertura.xml;reportdirectory=/workspace/_temp/cchtml;]
Async Command Start: Publish code coverage
Publishing coverage summary data to TFS server.
 Lines- 9255 of 39348 covered.
 Branches- 650 of 5041 covered.
Modifying Cobertura Index file
Publishing code coverage files to TFS server.
Uploading 3 files
##[debug]File: '/workspace/_temp/cchtml/index.htm' took 395 milliseconds to finish upload
##[debug]Detail upload trace for file: Code Coverage Report_814055/index.htm
##[debug]File 'Code Coverage Report_814055/index.htm' will be uploaded in one chunk.
##[debug]Attempt '1' for uploading chunk '1' of file 'Code Coverage Report_814055/index.htm'.
##[debug]Generate new HttpRequest for uploading file 'Code Coverage Report_814055/index.htm', chunk '1' of '1'.
##[debug]Start uploading file 'Code Coverage Report_814055/index.htm' to server, chunk '1'.
##[debug]Finished upload chunk '1' of file 'Code Coverage Report_814055/index.htm', elapsed 347 (ms), response code 'Created'.
##[debug]File: '/workspace/_temp/cchtml/index.html' took 399 milliseconds to finish upload

Expected behavior

Code coverage results should be published to SonarQube and available on the dashboard. Also the generated XML and HTML reports should indicate code coverage.

What build tool are you using?

Maven

Version of scoverage

v1.4.11

ckipp01 commented 1 year ago

Thanks for the report @Schuits.

I'm using Maven,scala version 2.11.12, java and scoverage-maven-plugin.

It's a bit hard to tell because if you're on 2.11.x still that means you're on a fairly old version of scoverage, which is no longer supported. There were some recent fixes for cobertura reports, but they only apply to the 2.x series.

Schuits commented 1 year ago

I managed to fix my problem, though I don't remember how. I think moving the generation of the coverage file to after I switch to Java11 did the trick.

I still cannot get the coverage results in SonarQube, but I think that has more to do with that tool than scoverage, so I've asked them for assistance.

Thanks