Exclude with sonar.exclusions property but it doesn't work

When I run the sonar CLI to scan a java project. It shows the message like this:

Your project contains .java files, please provide compiled classes with sonar.java.binaries property, or exclude them from the analysis with sonar.exclusions property.

I have tried the sonar.java.binaries property then It works.
And when I tried the sonar.exclusions property with the same patterns, It doesn’t work.

Hey there.

sonar.java.binaries is meant to be used to correctly configure the analysis, while sonar.exclusions would be used to exclude Java entirely (if, for example, you had some Java files sitting in a repo you didn’t actually mean to analyze).

Ideally, you are not using the Scanner CLI but using the Scanner for Maven or Scanner for Gradle (depending on your build system) which automatically configures properties like sonar.java.binaries for you from the build context.

Ideally, you are not using the Scanner CLI but using the Scanner for Maven or Scanner for Gradle (depending on your build system) which automatically configures properties like sonar.java.binaries for you from the build context.

When I used the Sonar plugin for Gradle, it still had the same issue, and I added the Java binaries to the sonar.exclusions. Then it can work as usual.