Sonar qube issue

Hi Team While uploading my sonar analysis to sonar qube my test case folder is uploading how to avoid it

Hey there.

Have you tried narrowing the focus?

Screenshot 2023-04-13 at 4.45.58 PM
I am sharing my folder structure and the arguments we pass in sonar anayalsis
mvn clean -U test -Dmaven.test.failure.ignore=true sonar:sonar${params.ALM_ORG_ID} -Dsonar.projectKey=${params.ALM_ORG_ID}.api-facade-metadataapi -Dsonar.coverage.exclusions=src/test/java/**/*.java, -Dsonar.projectName='CXU Metadata API' -Dsonar.sources=src/main -Dsonar.test=src/test -Dsonar.exclusions=src/test/**,src/main/resources/*,src/main/java/com/oracle/cxunity/metadata/,src/main/java/com/oracle/cxunity/metadata/model/*,src/main/java/com/oracle/cxunity/metadata/service/ -Dsonar.junit.reportPaths=target/surefire-reports/

Hey there.

If you’e using the Scanner for Maven, you should be able to simplify this to:

mvn clean -U test -Dmaven.test.failure.ignore=true sonar:sonar${params.ALM_ORG_ID} -Dsonar.projectKey=${params.ALM_ORG_ID}.api-facade-metadataapi -Dsonar.projectName='CXU Metadata API'

The Scanner for Maven automatically detects sources/tests, and passing information manually just gets in the way.

I suggest simplifying this, and then going back to see what exclusions you really need to add.

should i remove source and test arguments and run the command

Yes, that’s what I mean by simplifying it. Let the autodetection takes its course, and then add exclusions if still necessary.

sh "mvn clean -U test -Dmaven.test.failure.ignore=true sonar:sonar${params.ALM_ORG_ID} -Dsonar.projectKey=${params.ALM_ORG_ID}.api-facade-metadataapi -Dsonar.projectName=‘CXU Metadata API’ -Dsonar.exclusions=src/test/**/,src/main/resources/ -Dsonar.junit.reportPaths=target/surefire-reports/ "

Still my test folders are appearing in analysis

@Colin any update

Hey there.

This is a community forum, not a Service Desk. Please don’t bump threads after 2 hours, and refer to our FAQ.

Sorry can you help me to resolve the above issues

Hey there.

Stepping back for a moment, I realized that you’re experiencing expected behavior.

  • Source and Test files are analyzed
  • Only source files have “Lines of Code” (counting towards a license, if you have a commercial edition)
  • Some issues are still being raised on test files.

Can you clarify why you want to exclude the test files?

In test files it is reporting the issues which we dont want to fix .thats why we need to exclude them for m analysis

I would suggest marking these issues as Won’t Fix in the SonarQube UI, rather than excluding test files entirely and missing out on issues raised in the future you may actually want to fix!