Sonar Gradle plugin with version catalog

Hello I am trying to add Sonar Gradle plugin in Android project. I add it in root build.gradle.kt file as per documentation here SonarScanner for Gradle


plugins {

followed by properties declarations

sonar {
    properties {
        property("sonar.projectKey", "MY_KEY")
        property("", "MY_HOST_URL")
        property("sonar.projectName", "PROJECT_NAME")
        property("sonar.gradle.skipCompile", "true")

However recently we migrated to version catalog and I tried to updated plugins to

plugins {
    alias(libs.plugins.sonarqube) apply false

sonarqube = { id = "org.sonarqube", version.ref = "sonarqube"}

However this will not build as sonar properties block is not recognised. Is there any reason for it?

Hello @Peter_Miklosko ,

Unfortunately, I am not able to reproduce the issue you are seeing. I do not see the sonarqube version declared in your versions catalog example, could this be the issue?

If not, it would greatly help if you could create a small reproducer project that demonstrates the issue, such that I can investigate further.

My apologies I was on leave in December.
Please find a sample Android project here with sonar plugin setup as discussed above

1 Like

Hello, any further advice on this issue?

Hello Peter,

Please excuse the delay in the topic.

I’ve had a look at your project and noticed that the Sonar plugin is never actually applied to the project. This causes the sonar config block to not be recognized. You can remove the apply false after the Sonar plugin declaration and it should recognize the sonar block.

If you are using the apply false to avoid applying the sonar plugin in all subprojects, you will instead need to apply it in the subprojects you do want to run the sonar analysis. If you don’t want to do this manually for each submodule, you can look into the subprojects and allprojects blocks.

Thank you @jbeleites that work. I will close this treat and create new if anything else pop-up.

PS: Perhaps it would be a good idea to mention not to use apply false in the documentation, Android developers, we tend to overlook it :sweat_smile:

1 Like

I’m happy to read that it now works!

Thanks for the feedback, that might indeed be something to update in the documentation. Could you give me a link to the documentation that contains the apply false, so that I can have a look into updating it?

Documentation only mentions id("org.sonarqube").version(""), but given in our project we already using Gradle version catalogue I automatically assumed that it should be translated as alias(libs.plugins.sonarqube) apply false

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