Hello,
We made a change in the SonarScanner for Gradle so you can control when your code is compiled.
Until today, the SonarScanner for Gradle was behaving like this:
- when you were running
gradle sonar
, under the hood, it was triggering/forcing the compilation - this was a hard dependency and it was not possible to deactivate it
We made this design choice years ago because, for Java and Kotlin code, the Sonar analyzers must have access to the bytecode to perform an accurate analysis. So forcing the compilation to happen before the scan was a natural choice to be sure to run the scan in good conditions.
The problems of this approach are:
- you are forced to compile all the targets and for Android projects, you may not want to do that for each scan
- you canāt easily compile with one JDK version and run the scan with another version / itās possible but painful because you have to be explicit with the list of compile steps you donāt want to execute while running the sonar task
For these reasons, we decided to align the behavior of the SonarScanner for Gradle with the Maven one.
Our plan is to request users to be explicit and say:
gradle assemble sonar
ā¦ instead of just:
gradle sonar
The change will happen incrementally to not break all CI configurations:
- we introduced with v4.4.1 a property to allow users to adopt the new behavior
- a message will be displayed to invite you to move to the new behavior because the old one is now considered deprecated
- the SonarQube and SonarCloudās documentations/tutorials will be updated accordingly
- later we will change the default behavior with the v5.x and no longer force the compilation step
If you want to jump in now, you have to upgrade your SonarScanner for Gradle to v4.4.1 and set the property āsonar.gradle.skipCompileā to ātrueā.
Alex