Azure Devops pipeline not publishing code coverage results in Sonarcloud for Java project

We have a Java project and it will be executed in Azure Devops pipeline. Recently we configured Sonarcloud for Analysis and Code coverage, and the Analysis is happening and code coverage always shows as 0.0% but the test cases are executed during execution.

- task: SonarCloudPublish@1
  inputs:
    pollingTimeoutSec: '300'
- task: PublishCodeCoverageResults@1
  inputs:
    codeCoverageTool: 'JaCoCo'
    summaryFileLocation: '**/jacoco-aggregate/jacoco.xml'

I have used PublishCodeCoverageResults task and came to know this will be used to publish coverage in Azure itself. But Which task in Azure has to be used for publishing in Sonarcloud ? Can someone provide inputs on the same ? Thanks!

Hey there.

What are you using to build your Java project? Maven? Gradle?

Maven

I would suggest you start here:

This will ensure the JaCoCo XML report is created after your test execution – it’s possible you need to do no further configuration after this as long as the reports land in the default location. Coverage reports are imported during the sonar:sonar maven goal – no additional tasks required.

Out of curiosity – does your PublishCodeCoverageResults task already work (are coverage details being published to Azure?)