ajoberstar / reckon

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

How to set the stage for an included build when using composites. #197

Open grumpheim opened 1 year ago

grumpheim commented 1 year ago

I am using Gradle composites to build a set of projects. Some, but not all, of the projects use the Reckon plugin. (Gradle 7.4.2, Reckon 0.16.0 )

This setup works very well for development. My issue arises when I try to use this approach to create a release version of one of the Reckon-enabled projects.

When working with the project on its own, generating a release is simple: my_project_dir% gradle build -Preckon.stage=final

I would like to be able to do the same with the composite:

composite_dir% gradle :my_project:build -Preckon.stage=final

This doesn't produce a release. I reviewed the issues (https://github.com/ajoberstar/reckon/issues/74) and it looks like this is intentional: The intended behavior is not clear. I understand and agree. But is there a (sane) way for me to get my use-case to work? Creating a release from one of the sub-projects seems like a valid use-case. I would like to get it to work without editing files, if possible. I think my ask can be summarized as:

"Given that at least one sub-project in a Gradle composite is Reckon-aware, how can I configure the build so that specific project is configured with reckon.stage=final?"

This would allow me to use composite builds in my CICD system.


I've tried some casual experiments just to see how/if reckon.scope was being propagated in the composite.

These failures led me to think I'm missing something basic, which is why I'm here :-)

grumpheim commented 1 year ago

In the version of reckon that I'm using (0.16.0), the fix referenced above is implemented differently. The providers for stage and scope are modified with 'forUseAtConfigurationTime()'

This means that I can override this in my project:

` reckon { scopeFromProp() stageFromProp('beta', 'rc', 'final')

// WARNING: Subtle and brittle stage.set(project.getProviders().gradleProperty('reckon.stage')) scope.set(project.getProviders().gradleProperty('reckon.scope')) } `

This has the effect of re-enabling the providers, even if we are in a composite.

This workaround is good enough for my narrow case (only one reckon-enabled project in a composite). But I don't consider it a real solution, especially since forUseAtConfigurationTime is deprecated.