Sonar Eclipse plug-in Vs Gradle Sonar-Runner Plugin : JUnit test Java files code quality differences

I am using SonarQube Eclipse plug-in for Java projects to analysis code quality for both source Java files & test (JUnit) Java files. And CI build server makes use of Gradle and Sonar-Runner plugin to run Sonar quality profile and post the final results to SonarQube Server.

When I edited a test-case(JUnit Java file) to just use “Clean Up”{ NO major changes to the code ,making use ‘final’ keyword to local variable in the test case if possible} operation from Eclipse and run Sonar “Analysis” locally (in Incremental mode), I do see some Critical issues on the test java file which are legitimate issues. Sonar-runner plug-in from Gradle CI server has been running on the project every day for past few months now but SonarQube server does not show the same result.

Could anyone explain why to do I see 2 different results (SonarQube Eclipse plug-in Vs Gradle SonarQube Server)?

Details: Sonar Eclipse plug-in : 3.4 SonarQube : 4.0 Gradle : 2.1 Sonar properties uses default settings to identify source-set (‘main’) and test-set (‘test’).

I guess it depends which code quality rules the Eclipse plugin has enabled, and whether they are the same as those configured in SonarQube. I don’t know if the Eclipse plugin queries SonarQube to get the rules, like Sonar Runner does.

Hi Peter,

Thanks for the quick reply. The Eclipse SonarQube plugin console log says it is fetching and using SonarQube server quality profile. I think, basically Eclipse plugin uses Sonar-Runner in background.

Retrieve remote issues of project JavaProject… Start SonarQube analysis on JavaProject… INFO: SonarQube Server 4.0 15:49:08.853 INFO - Incremental mode 15:49:08.869 INFO - Load batch settings 15:49:09.181 INFO - User cache: C:\Users\user.sonar\cache 15:49:09.196 INFO - Install plugins 15:49:09.430 INFO - Exclude plugins: devcockpit, jira, pdfreport, views, report, scmactivity 15:49:12.662 INFO - Create JDBC datasource for jdbc:h2:D:\VxFutureWorkspace.metadata.plugins\org.eclipse.core.resources.projects\JavaProject\org.sonar.ide.eclipse.core.sonartmp\preview1417448950902-0 15:49:14.381 INFO - Initializing Hibernate 15:49:15.912 INFO - Load project settings 15:49:16.194 INFO - To enable the analysis bootstraper for Visual Studio projects, set the property “sonar.visualstudio.enable” to “true” 15:49:16.195 INFO - Apply project exclusions 15:49:16.344 INFO - ------------- Scan JavaProject 15:49:16.344 INFO - Load module settings 15:49:16.929 INFO - Quality profile : [name=Sonar way with Findbugs,language=java] 15:49:16.939 INFO - Excluded sources:

15:49:16.939 INFO -

file:/libjpeg/ 15:49:16.939 INFO -

file:/re_Lib/ 15:49:16.939 INFO -

file:**/_dictionary.h 15:49:16.939 INFO -

file:**/AssemblyInfo.cpp

Let me know if you need any more information.

BR> HIC

Gradle is using Sonar Runner as well. I recommend to take this to the SonarQube mailing list.

I’m trying to understand what you’re describing here.

You’re saying that you’ve made local changes to a file, and you’re finding that the results from a local analysis don’t match what you see on the CI server? You haven’t really provided any details here, but if that’s all you’re telling us, then that’s perfectly understandable. A local analysis analyzes local changes. The CI server only analyzes checked in code.

How about you provide more details, and describe exactly what you’re seeing that shouldn’t be happening?

Thanks Peter. I am in touch with SonarQube mailing list. Here is quick summary: SonarQube should not be analysing test source code as it not supported properly by SonarQube.

First configurations using zip downloads:

SonarQube -4.5.1/4.0

Sonar Runner- 2.3/2.4

These configurations yield the same results i.e. test source files are not at all analysed

Second Configuration with Eclipse:

I am using SonarQube Eclipse plug-in 3.4 with SonarQube 4.0; this configuration should have behaved as that of first configuration but not, this analyses test source code too.

Note : SonarQube Eclipse plug-in 3.4 makes uses of Sonar Runner API Eclipse plug-in 2.3.0.

I suspect it is problem with Sonar Eclipse plug-in 3.4 or Sonar Runner API Eclipse plug-in 2.3.0.

BR> HIC

Hi David, Thanks for the support.

Here is quick summary update about the discuss with SonarQube team/forum regarding the issue:

SonarQube should not be analysing test source code as it not supported properly by SonarQube.

First configurations using zip downloads:

SonarQube -4.5.1/4.0

Sonar Runner- 2.3/2.4

These configurations yield the same results i.e. test source files are not at all analysed

Second Configuration with Eclipse:

I am using SonarQube Eclipse plug-in 3.4 with SonarQube 4.0; this configuration should have behaved as that of first configuration but not, this analyses test source code too.

Note : SonarQube Eclipse plug-in 3.4 makes uses of Sonar Runner API Eclipse plug-in 2.3.0.

I suspect it is problem with Sonar Eclipse plug-in 3.4 or Sonar Runner API Eclipse plug-in 2.3.0.

BR>

HIC