sonar.gradle.skipCompile is not working

We updated to 4.4.1.3373 and now try to migrate to the new sonar.gradle.skipCompile behavior.

No matter how we set this property, we always get the deprecation warning while Gradle configuration.

The ‘sonar’ task depends on compile tasks. This behavior is now deprecated and will be removed in version 5.x. To avoid implicit compilation, set property ‘sonar.gradle.skipCompile’ to ‘true’ and make sure your project is compiled, before analysis has started.

For me this looks like an error in the plugin implementation:
Instead of trying to read the property from system properties directly (https://github.com/SonarSource/sonar-scanner-gradle/blob/391069a27ae3f5c1d806e6380bb2fdd54c63c815/src/main/java/org/sonarqube/gradle/SonarQubePlugin.java#L113) the properties should be read from the computed SonarProperties like in this line https://github.com/SonarSource/sonar-scanner-gradle/blob/391069a27ae3f5c1d806e6380bb2fdd54c63c815/src/main/java/org/sonarqube/gradle/SonarQubePlugin.java#L108.

Otherwise it seems like SonarQube Plugin is not able to find this property, even though it is set next to all the other properties in the SonarExtension block.

1 Like

I noticed the same issue. If you set the flag as an argument, it works:

./gradlew sonar -Dsonar.gradle.skipCompile=true

But when you set it as a property:

property("sonar.gradle.skipCompile", true)

It does not.

2 Likes

Even this is not working out in our Android multi module project. Already tried to set this property via properties.gradle and gradle command line argument. We still get the deprecation warning.

Edit: Thanks to this post I was able to make it work.

The code says, that it’s a system property. So it has to be systemProp.sonar.gradle.skipCompile=true in gradle.properties.

But even with this option Gradle still compiles and executes the tests again.

So ./gradlew sonar -x test ... still seems to be the only option to suppress that.

Have you tried adding
System.setProperty("sonar.gradle.skipCompile", "true")
to settings.gradle(.kts)?

I think it happens because SonarQubePlugin checks property value from environment, but not from passed properties collection

boolean skipImplicitCompilation = Boolean.getBoolean(“sonar.gradle.skipCompile”);

Thanks, @G00fY2 @JonatanPlesko @markusheiden @bostandyksoft for noticing this. Indeed the property is read from the System properties, instead of sonar properties. Here is the ticket to fix it: [SONARGRADL-134] - Jira.

However, this property was supposed to be just for transition to make sure you stopped relying on the behavior of compiling implicitly. In version 5.0+ this property will disappear and there won’t be a dependency between the sonar task and compile* tasks.

We will try to apply the fix in the next minor release or drop the property completely in the next major release. Meanwhile, the workaround is to set the System property. Sorry for the inconvenience.

Best,
Margarita

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.