Sonarlint running locally does not catch parent pom.xml rule exclusion


My configuration:

  • Operating system: Ubutu Linux 22.04.1
  • SonarLint plugin version:
  • Programming language: Java
  • IDE: IntelliJ IDEA 2022.2.3 (Community Edition)
  • Connected to SonarCloud

In my project, we have a all folder called tck (test compatibility kit) used for testing with many subfolders and files.

On the following code:

public interface IStatisticsTck extends ITckBase {

	default void required_getEmptySize() {
		final long emptySize = function()

SonarLint marks the bug java:S5960 (Assertions should not be used in production code) for the line assertThat

The issue is that it is not supposed to happen.
Indeed, at the root of the tck folder, in the pom.xml, there is the entry:

		<!-- Test project, all sources are tests -->

On SonarCloud, it is correctly excluded from the analysis, but locally, when running the analysis on the file IStatisticsTck, it reports the false positive.

Is it a bug of SonarLint or a configuration issue ?

Best regards,

Hi @NathanEckert

SonarLint and SonarCloud analysis configurations follow a different approach. SonarCloud uses one of the SonarScanners (here I guess you are using the scanner for Maven). The scanner for Maven will try to infer your project structure from the Maven model. For special cases like yours, you can override the scanner behavior using properties sonar.sources and sonar.tests.

SonarLint on its side relies on IDE metadata. IDEs like IntelliJ already have their own way to “understand” Maven project structure, and deciding what is test and what is production code.

Basically, SonarLint will respect what you see in the IDEA project structure:

We think SonarLint behavior should be consistent with what you see in your IDE (green folder = test, blue folder = main code).

So one simple way to fix your problem is to let IntelliJ know that the folder src is a test folder, by manually changing the folder type in the project structure.

In the long run, it might be better to also let Maven knows, and declare that your src folder is a test folder, using something like:


This way, when Intellij will import your project, it will automatically know that src is a test folder. And it should also automatically be picked by the scanner for Maven.

But this might be a bit tricky, since I guess your tck is a kind of reusable test library, so you want tests to be packaged. You can try to follow this Maven guide.


Thanks a lot for your answer. Unfortunately, Maven does not have the concept of “test project” and using the tag testSourceDirectory does not fix the issue.

I can solve the issue for myself with your solution but cannot share it with other repository’s contributors.