Plugin that modifies the version - when to execute?

Hi,

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="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>t31.plugins.versionnumber</groupId>
  <artifactId>t31.plugins.versionnumber.gradle.plugin</artifactId>
  <version>0.1.4</version>
  <packaging>pom</packaging>
  <dependencies>
    <dependency>
      <groupId>de.t31</groupId>
      <artifactId>t31plugins</artifactId>
      <version>0.1.+</version>
    </dependency>
  </dependencies>
</project>

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, …