SonarQube Scanner for Gradle uses the Convention Mapping API without cacheability

My company has certain scanner properties configuration that is in common with most of their projects. I would like to create a Gradle plugin that applies the SonarQube Scanner plugin for Gradle, sets some meaningful defaults, and checks if the final configuration looks valid.

While I can nicely control the default values using {} blocks, I ran into an issue with the validation of the final properties (which also check system properties). Let’s say I add an action or a task dependency to the sonarqube task, which calls the getter. The task Convention Mapping API will respond with the calculated properties. However, when the sonarqube task calls the getter too, this calculation is performed again (because it happens each time we call the getter). And this field is read only, as it has no setter. So I cannot influence Gradle to cache the calculation results. This is a bit unoptimal. I wouldn’t say it often results in a huge execution delay to really worry about, I just find it an unfortunate design that may not scale well with expensive property configuration action blocks. Plus plugin authors will have to remember to call the getter only once (or as few times as possible).

By the way you probably know that the convention mapping API is no longer recommended in favor of Extensions and Lazy Properties, but that might be for another story, rather than here.

Hey there.

Thanks for the report. I believe we already have a ticket open for this: [SONARGRADL-92] sonarqube task doesn't detect cached configuration - SonarSource

Hi, Colin,

I cannot fully confirm that these are the same issues, although they are indeed similar. I wasn’t talking about Gradle’s configuration cache (I haven’t even heard of that feature until now to be honest), but about in-memory caching of properties computations so I don’t accidentally calculate them twice, that is, in my own Gradle plugin too while using yours. But if the solution of that other issue is going to work for my issue too, which I actually find likely, then that’s completely fine.

I’ll send this over to the right team just to double check, as honestly, I don’t know that much about the Gradle ecosystem.

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