I have a project defining multiple convention plugins, all published under the same version. To keep things compatible and to not have the client projects repeat the same version string multiple times, I want to have a way for the clients to apply a single settings plugin at a specified version and have all the other convention plugins automatically be at the same version.
To that end, I added a settings convention plugin to my convention plugins project and created a version catalog in it but at that point I don’t know how to get the version of this project.
version("conventions", "what do I put here to get the version of this plugin?")
I’m also using this settings convention plugin to set up some other things.
Thanks in advance!
Generate the version to some resource, like having a properties file with a placeholder and using
expand in the
processResources task, then you can read the version from that file at runtime.
There is no built-in “give me my version” for Gradle plugins, as depending on details Gradle even could not know the version, so if a plugin needs to know its own version, it needs to make this possible itself.
But to align the version of multiple artifacts, you should instead consider using proper version alignment as for example described at Automatically align Dependencies with Platforms and Gradle Module Metadata
Thanks! I’m assuming this must be working out of the box, because I later realized that when I applied the settings plugin, the remaining convention plugins were automatically applied at the same version.
The version alignment is not working out-of-the-box.
But if you have the settings plugin and the other convention plugins within one project and thus within one JAR, then it probably has the effect you want, as applying the settings plugin brings the whole JAR to the classpath and thus the convention plugins are there with the intended version already and you can apply them without version.