SonarScanner gradle plugin - build.gradle not indexed by default

Hi,

I am currently experimenting writing a plugin where I would like to create new issues for a gradle project where I run the scan with the gradle plugin. I tried to create the issues against the build.gradle file but this didn’t work as build.gradle is not being indexed by default. I can only make it work by adding this file explicitly to the sonar.sources property.
Additionally, when I use Kotlin for the build file, i.e. build.gradle.kts, then the file does get indexed by default.

I would like to understand why the behaviour is different between the two approaches?

Note I have used SonarQube version 9.9 for this.

Many thanks,

Gordon

Hi Gordon,

Welcome to the community!

Google is telling me that .kts is a ‘normal’ Kotlin file. So this is not about ignoring the build file necessarily, but about picking up ‘recognized’ source files. .kts is a recognized file extension, whereas .gradle is not.

 
HTH,
Ann

build.gradle is a groovy file, so you may use groovy plugin.

See Does sonarqube support scanning groovy language?.

Note: sonar-groovy is not maintained anymore, but one of the forks seems to be updated to work with 10.6 (from reading the commit name, I haven’t tested it myself).

You’ll have to add .gradle to groovy suffixes: sonar-groovy/sonar-groovy-plugin/src/main/java/org/sonar/plugins/groovy/foundation/Groovy.java at main · Inform-Software/sonar-groovy · GitHub

Of course, there are no gradle-specific rules. It seems that noone has written them…

Jano

1 Like