Sonarqube jacoco code coverage exclusion not works

We are using Sonarqube on our server and when we are triggering build of maven from TFS (Azure Devops) using the CI yaml pipeline.
Sonarqube step is having exclusion but it fails to exclude the class and issue occurs of Jacoco ant exception.

Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.8:run (default) on project VstsReport: An Ant BuildException has occured: Error while creating report
[ERROR] around Ant part …… @ 8:11 in /buildagent/_work/2/s/com.avl.data/target/antrun/build-main.xml: Error while analyzing messagebroker-consumer-app/target/messagebroker-consumer-app-1.0-SNAPSHOT.jar@BOOT-INF/lib/zookeeper-3.4.14.jar@org/apache/jute/BinaryInputArchive$BinaryIndex.class. Can’t add different class with same name: org/apache/jute/BinaryInputArchive$BinaryIndex

  scannerMode: 'Other'
  extraProperties: |
    sonar.exclusions= **/*.bin,org/apache/jute/*.class
    sonar.coverage.exclusions= $(System.DefaultWorkingDirectory)/target/antrun/**,**/org/apache/jute/*.class
    sonar.projectVersion= '$(Build.BuildNumber)'
    sonar.verbose= true

Hi,

Welcome to the community!

Do you have multiple classes in your project with the same name?

Also, you mention the use of Maven, but then say you’re getting an Ant error. Please tell me you’re not executing Ant from Maven…?

 
Ann

Yes we have multiple classes in the project, but i am not able to find them as it says some build class error

/buildagent/_work/2/s/com.avl.data/target/antrun/build-main.xml: Error while analyzing messagebroker-consumer-app/target/messagebroker-consumer-app-1.0-SNAPSHOT.jar@BOOT-INF/lib/zookeeper-3.4.14.jar@org/apache/jute/BinaryInputArchive$BinaryIndex.class. Can’t add different class with same name: org/apache/jute/BinaryInputArchive$BinaryIndex

We are using maven and then ant is utilised from it.

Hi,

Whether or not you have multiple classes in the project was not the question; my assumption was that you did. The error says you have multiple classes with the same name. Is that the case?

As for how you’re performing analysis, there’s no good reason to call the Ant analyzer from Maven. If you have a Maven project, then perform a Maven analysis (mvn sonar:sonar). If you don’t have a Maven project, then just use the CLI SonarScanner (or perhaps you have a Gradle project?) And if you actually have an Ant project, well… I’d exec the CLI SonarScanner from your Ant file.

 
Ann

Yes your assumption is right, i am not able to find that project’s folder which needs to be excluded here and name are same somehow as per error for the class.

And we are performing maven build, sonarscanning and jacoco scans using TFS (azure devops).
And as per error it is maven integrate project.
Not gradle.

As in our maven build locally, there comes a folder for the maven dependency and when i am building the same with the Azure Devops, this folder is not build and somehow i need to find out which target folder or directory to add into exclusion of sonar.coverage.exclusion.

Hi,

I would start by excluding everything, using a list of directories. Analyze that & make sure it works. Then you can slowly delete from the list to add things back in.

Does that make sense?

 
Ann

This is not working, i tried using adding the jacoco exlusions, but it doesn’t excludes as it should.
Seems a system bug in Sonarqube.

Also i used the new version of sonarqube 7.9.1 but still same issue and error.

    sonar.coverage.exclusions= /buildagent/_work/1/s/com.avl.data/messagebroker-consumer-app/target/**
    sonar.projectVersion= '$(Build.BuildNumber)'
    sonar.projectName= avl.data.java

Still it fails and reflects error.

Hi,

Generally, I recommend setting exclusions through the UI. But okay.

First, there’s no reason to set the path from box root. in fact, that’s probably why your exclusions aren’t kicking in; they’re assumed to start from project root. Second, you’ve set an exclusion on directories ("**"), not files. Not sure that will work.

To exclude everything, try this:

sonar.coverage.exclusions=**/*.*

Alternately, to do it in a format that will later make it easy to subtract from:

sonar.coverage.exclusions=**/dir1/**/*.*,**/dir2/**/*.*,**/dir3/**/*.*

Then, in line with my earlier advice, once you’ve got that working as expected, you can start whittling the list down:

sonar.coverage.exclusions=**/dir1/**/*.*,**/dir2/**/*.*

 
HTH,
Ann

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.8:run (default) on project VstsReport: An Ant BuildException has occured: Error while creating report

[ERROR] around Ant part …… @ 8:11 in /buildagent/_work/1/s/com.avl.data/target/antrun/build-main.xml: Error while analyzing messagebroker-consumer-app/target/messagebroker-consumer-app-1.0-SNAPSHOT.jar@BOOT-INF/lib/zookeeper-3.4.14.jar@org/apache/jute/BinaryInputArchive$BinaryIndex.class. Can’t add different class with same name: org/apache/jute/BinaryInputArchive$BinaryIndex

[ERROR] -> [Help 1]

Still there is error after using the all exclusion.
sonar.coverage.exclusions=**/.

Hi,

The exclusion you used doesn’t match any of the ones I recommended. You still didn’t actually exclude anything.

 
Ann