hey everybody! I don't know if this is the best ch...
# gradle
m
hey everybody! I don't know if this is the best channel to post this but I'm investigating why our
sonarqube
is taking almost 6 minutes to run, when it should just run
androidVariant "devXXDebug"
, but I still see tasks such as
compileProdXXDebugAndroidTestKotlin
being compiled - is this normal? should this task be compiled when according to the
androidVariant
it should only compile
devXXDebug
?
v
As your question is not really Kotlin related as far as I can tell, it probably is not. It might be better suited for an Android community. :-)
m
definitely! Thanks @Vampire!
a
Unfortunately the sonarqube Gradle plugin is really non-idiomatic, and breaks a lot of the standard Gradle conventions, so I would be grateful if it worked at all(!)
m
really? so it looks like I couldn't really avoid having sonarqube compile prod variants?
a
anything is possible!
m
yeah, the question is how 🙂
a
re-write the Sonarqube Gradle plugin 🙃
alternatively, maybe it’s possible to use the existing Sonarqube Gradle tasks and amend them or set them up yourself, so they only target the correct variants
m
yeah that's what I've been trying but I'm unable to do it. I also didn't find anybody else who had the same issue, so I'm just wondering if this is the normal and default behaviour
a
I looked into trying to get the Sonar GP working on a Kotlin Multiplatform project (before I realised there’s no Sonar analysis backend for Kotlin Multiplatform projects, so it was a waste of time), and it was really difficult
how familiar are you with writing Gradle plugins, or configuring tasks?
m
close to 0
butI can try!
a
haha okay
everyone starts from somewhere!
m
exactly
a
in short: • Gradle Tasks are the units of work. They accept files and properties as inputs, and they produce files as outputs. • Gradle Tasks inputs can be files that are the outputs of other tasks, and so Gradle can be clever and chain tasks together. • I presume when the Sonarqube GP is setting up the Sonarqube analysis task it’s adding all Android compilations as inputs - which is not what you want!
this looks like the likely cause:
Copy code
sonarTask.mustRunAfter(getJavaTestTasks(project));
    sonarTask.dependsOn(getJavaCompileTasks(project));
    sonarTask.mustRunAfter(getJacocoTasks(project));
    sonarTask.dependsOn(getAndroidCompileTasks(project));
https://github.com/SonarSource/sonar-scanner-gradle/blob/81638cca447d6a68d51b47b83e99c1ea3cdb6801/src/main/java/org/sonarqube/gradle/SonarQubePlugin.java#L113-L116
so I would guess that
getAndroidCompileTasks(project)
is fetching all Android compilation tasks
now that I think about it, it’s likely that Sonarqube has a way to disable analysis for specific compilations…
anyway, either you can • try and find some property to disable the Android compilations you want to ignore (and the Sonar properties are not well documented, so… good luck!). • Or you can copy&paste the same task configuration as the Sonar Gradle plugin, but only add the specific tasks you want to run. (And disable the task that the Sonar GP is adding, so you don’t accidentally run the wrong one)
but unfortunately the Sonar GP is using a lot of bad practice (like using
getAllprojects()
and not using the Provider API), so it’s going to be really hard to try and get something working because you’ll be trying to workaround workarounds, which will probably require more workarounds….
Another alternative: you could try manually excluding the tasks
Copy code
./gradlew sonar -x compileProdXXDebugAndroidTestKotlin
It’s more manual, harder to maintain, but it’s easier to understand and implement!
v
You can also set
dependsOn
to an empty list / the list of task you want as dependencies
m
thanks!
I'll try with the -x
I don't know if this is all Bitrise's fault, because locally, it takes way less than the 5.5 minutes it takes in bitrise
unfortunately, the -x makes no difference as it's still taking 5.5 minutes