ajoberstar / reckon

Infer a project's version from your Git repository.
Apache License 2.0
185 stars 28 forks source link

Provide some public API to determine if a release or snapshot will be build #150

Closed jnehlmeier closed 2 years ago

jnehlmeier commented 3 years ago

I am updating a defaults plugin for our projects and noticed that this plugin needs to decide during Gradle configuration time which Maven repository should be used based on the project version. This check triggers reckon to compute the version which could take some time since git work is involved.

The defaults plugin basically does:

project.getExtensions.configure(PublishingExtension.class, publishing -> {
      // .....
      publishing.repositories(artifactRepositories -> {
        artifactRepositories.maven(mavenArtifactRepository -> {
          // -----------
          // reckon is triggered here and I would like to avoid it somehow
          // -----------
          var isSnapshotPublication = prj.getVersion().toString().endsWith("SNAPSHOT");
          var repo = isSnapshotPublication ? "snapshots" : "releases";
          mavenArtifactRepository.setUrl("https://example.com/maven/" + repo);
        });
      });
    });

Of course I could use some logic to read the reckon.stage property but then I would replicate what reckon is already doing and have the risk that my logic might become incorrect if reckon changes in the future. So I would like to see some public API in reckon that does not evaluate the actual version number using git but instead only evaluates if it's a release or a snapshot version.

ajoberstar commented 2 years ago

Now that in 0.14.0 you can get the Version from the extension, you can access the getStage for this use case.