Java custom rules executes via SonarLint , ONLY after Jenkins build execution( via. SonarQube)

Please provide

  • Operating system: Windows Server 2022
  • SonarLint plugin version: 10.3.0.77475
  • Intellij IDEA version : 2022.3.3
  • Programming language you’re coding in: Java
  • Is connected mode used: Yes
    • Connected to SonarCloud or SonarQube (and which version):
      SonarQube Community Edition Version 9.9.3 (build 79811)

And a thorough description of the problem / question:
Custom rule execution issue via. SonarLint.
Steps :

  1. A new quality profile is created in SonarQube and set as a DEFAULT profile.
  2. Few custom rules have been developed and activated in the default quality profile, along with “Sonar Way BUILT IN” rules
  3. In IntelliJ IDEA, Integrate SonarLint to SonarQube project and execute code analysis via SonarLint. Custom rules were NOT executed. The SonarLint tab displays the issues only from the “Sonar Way BUILT IN” rules. “Update local storage” has been clicked in the SonarLint settings and tried again - same output (“Found 0 issues and 0 hotspots”).
  4. With the same SonarQube configuration, Code analysis is performed via. Jenkins (Project “Build Now” operation). All custom rules are executed as expected in the SonarQube UI, along with “Sonar Way” ( all BUILT IN) rules.
  5. Now return to IntelliJ IDEA and execute code analysis via the SonarLint tab - All custom rules executed successfully, along with “Sonar Way” ( all BUILT IN) rules. Expected response received in SonarLint tab of IntelliJ IDEA.
    Question:
    Why SonarLint did NOT execute all the custom rules checks in step 3, but executed the same custom rules in the step 5 ( using the same SonarQube configuration)?
    Custom plugin was packaged using the sonarLintSupported = TRUE option in pom.xml
<plugin>
                <groupId>org.sonarsource.sonar-packaging-maven-plugin</groupId>
                <artifactId>sonar-packaging-maven-plugin</artifactId>
                <version>1.18.0.372</version>
                <extensions>true</extensions>
                <configuration>
                    <!-- the entry-point class that extends org.sonar.api.SonarPlugin -->
                    <pluginClass>com.mydemoproject.sonarqube.SonarPlugin</pluginClass>
                    <sonarLintSupported>true</sonarLintSupported>
                    <sonarQubeMinVersion>6.7</sonarQubeMinVersion>
                    <pluginDescription>sonarqube custom rules</pluginDescription>
                    <skipDependenciesPackaging>true</skipDependenciesPackaging>
                    <!-- properly declare dependency on SonarJava for SonarLint -->
                    <requirePlugins>java:5.11</requirePlugins>
                </configuration>
            </plugin>

Please advise if I am missing anything to execute the custom rules via SonarLint as we only like to use SonarLint for code analysis ( not via Jenkins’s Build → SonarQube for all projects).

Hi,

This is a great question. The key part is this:

That means that you set it as the profile to be used in the next analysis for each project not directly pinned to a specific profile.

As a rule, Quality Profiles don’t change that often, and it’s generally true that the profile used for the last analysis will be the profile that will be used for the next analysis.

I’ve never had to think this through before, but I suppose Connected Mode is picking up the last-used profile and applying that, rather than trying to calculate what the next-used profile will be.

It’s possible that you’d have had a different outcome if you’d explicitly pinned your project to the new profile, but I doubt it.

 
HTH,
Ann

Thank you for the reply. I have set the new “quality profile” as a default profile and set that in the project as a default quality profile. Custom rules have been activated in that quality profile. Connected mode did not pick up the custom rules until I executed the analysis via Jenkins for the same quality profile ( and same project). I thought the connected mode should execute the custom rules as like SonarQube ( via. Jenkins).

1 Like

Hi,

It was just a guess that assigning the project to the profile might work. And I’m not shocked that it didn’t.

Look at it from the other direction: if your new default profile raises more issues than the old one, it would look weird for SonarLint to have “extra” issues that don’t show up in SonarQube (until after the new analysis).

 
HTH,
Ann