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 sonarqube.properties {}
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 tasks.sonarqube.properties
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 tasks.sonarqube.properties
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.