Plugin that modifies the version - when to execute?


I have written a plugin that looks up the last published version in our repository and modifies the version-attribute in the build accordingly. In the build.gradle.kts a version = “0.1.+” get replaced with the correct buildnumber 0.1.4

Currently I execute it at project.afterEvaluate {}. But when I let Gradle generate the PluginMarkerMaven.pom for this project, the new version number appears correctly in the Tag of the plugin itself, but not in the -tag of the dependency to the plugin-jar.

<project xmlns="" xmlns:xsi="" xsi:schemaLocation="">

Is there a way to execute this right after the project-properties are set and before any other plugin uses them?

Apply your plugin first and don’t defer the version setting.
If you want to defer the version calculation until it is necessary, set the version to an object that does the calculation in the toString() method or from a lazily initialized field.

But I personally recommend to just not calculate versions dynamically.
Imho any version calculation by release infrastructure, VCS, or whatever dynamic source is bad.
That way you do not get reproducible builds, and you also cannot build outside that infrastructure.
If you e.g. use JGit to get the last tag and calculate the version from it, then you are already lost when you try to build from a secondary Git worktree as JGit cannot handle them. Same for shallow clones where the base for the calculation might not be available, …