-
Notifications
You must be signed in to change notification settings - Fork 74
Expose getVersionDetails() method on GitVersionPlugin #1156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
Generate changelog in
|
✅ Successfully generated changelog entry!Need to regenerate?Simply interact with the changelog bot comment again to regenerate these entries. 📋Changelog Preview💡 Improvements
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR exposes the getVersionDetails() method on GitVersionPlugin to enable programmatic access to version information. Previously, version details were only accessible through the gitVersion() closure or the printVersion task.
Changes:
- Added a public
getVersionDetails()method toGitVersionPluginthat returns aProvider<VersionDetails> - Refactored
GitVersionPluginto use constructor injection, storingProjectand service provider as instance fields - Removed
IOExceptionfromgetBranchName()method signature inVersionDetailsinterface
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/main/java/com/palantir/gradle/gitversion/VersionDetails.java | Removed IOException from getBranchName() signature for consistency |
| src/main/java/com/palantir/gradle/gitversion/GitVersionPlugin.java | Added constructor injection and exposed getVersionDetails() method |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| this.serviceProvider = GitVersionCacheService.getSharedGitVersionCacheService(project); | ||
| } | ||
|
|
||
| @Override | ||
| @SuppressWarnings("HiddenField") | ||
| public void apply(final Project project) { | ||
| project.getRootProject().getPluginManager().apply(GitVersionRootPlugin.class); |
Copilot
AI
Jan 13, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initializing the serviceProvider in the constructor before apply() is called may cause issues if the GitVersionRootPlugin hasn't been applied yet. The service provider initialization depends on the root plugin being applied first (which happens in apply() at line 41), but this constructor runs before that. Consider lazy initialization or moving the serviceProvider initialization to after the root plugin is applied.
| this.serviceProvider = GitVersionCacheService.getSharedGitVersionCacheService(project); | |
| } | |
| @Override | |
| @SuppressWarnings("HiddenField") | |
| public void apply(final Project project) { | |
| project.getRootProject().getPluginManager().apply(GitVersionRootPlugin.class); | |
| } | |
| @Override | |
| @SuppressWarnings("HiddenField") | |
| public void apply(final Project project) { | |
| project.getRootProject().getPluginManager().apply(GitVersionRootPlugin.class); | |
| this.serviceProvider = GitVersionCacheService.getSharedGitVersionCacheService(project); |
| @SuppressWarnings("HiddenField") | ||
| public void apply(final Project project) { |
Copilot
AI
Jan 13, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The @SuppressWarnings("HiddenField") suppresses a warning about the parameter hiding the instance field. Since the instance field is now stored in the constructor, consider using this.project instead of the parameter throughout the apply() method to avoid this suppression and potential confusion about which project reference is being used.
|
I feel like it's sufficient to just get the build service from wherever you plan to use this no? |
| private Project project; | ||
| private Provider<GitVersionCacheService> serviceProvider; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final
| private Project project; | ||
| private Provider<GitVersionCacheService> serviceProvider; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's call this cacheService
| } | ||
|
|
||
| @Override | ||
| @SuppressWarnings("HiddenField") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't think this applies anymore?
| }); | ||
| } | ||
|
|
||
| public Provider<VersionDetails> getVersionDetails() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we have to be careful here. It's not clear what will be selected when being referenced from buildscripts as getVersionDetails will be accessible via versionDetails in buildscripts (potentially).
I think the number of places where this actually works is limited since you have to get the result of the plugin application.
But now you have two methods that look very similar, but one returns a realised VersionDetails and the other returns a Provider<VersionDetails> . If I were scanning the code to see how something worked, I would not be surprised if I landed on this method, and got confused at what looks like magic, despite it actually being the closure method.
To resolve this, I think we should either:
- change the name of the method
- just get what we need by using the cache service directly instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also this method is not the same as what you get in the closure. You're always passing null to the details. IIRC this method was added for the internal frontend monorepo, so it's also not clear whether this gets you want you want.
Summary
Expose
getVersionDetails()method onGitVersionPluginto allow programmatic access to version details.Why
Previously, version details were only accessible through the
gitVersion()closure or by running theprintVersiontask. This change enables other Gradle plugins and build scripts to programmatically access detailed version information (branch name, git hash, etc.) through the plugin instance itselfExample Use Case
==COMMIT_MSG==
Expose getVersionDetails() method on GitVersionPlugin
==COMMIT_MSG==