Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/main/java/com/palantir/gradle/gitversion/GitVersionPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.palantir.gradle.gitversion;

import groovy.lang.Closure;
import javax.inject.Inject;
import org.gradle.api.Action;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
Expand All @@ -25,13 +26,20 @@

public final class GitVersionPlugin implements Plugin<Project> {

private Project project;
private Provider<GitVersionCacheService> serviceProvider;
Comment on lines +29 to +30

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final

Comment on lines +29 to +30

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


@Inject
public GitVersionPlugin(Project project) {
this.project = project;
this.serviceProvider = GitVersionCacheService.getSharedGitVersionCacheService(project);
}

@Override
@SuppressWarnings("HiddenField")

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 void apply(final Project project) {
Comment on lines +39 to 40
Copy link

Copilot AI Jan 13, 2026

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.

Copilot uses AI. Check for mistakes.
project.getRootProject().getPluginManager().apply(GitVersionRootPlugin.class);
Comment on lines +35 to 41
Copy link

Copilot AI Jan 13, 2026

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.

Suggested change
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);

Copilot uses AI. Check for mistakes.

Provider<GitVersionCacheService> serviceProvider =
GitVersionCacheService.getSharedGitVersionCacheService(project);

// intentionally not using .getExtension() here for back-compat
project.getExtensions().getExtraProperties().set("gitVersion", new Closure<String>(this, this) {
@SuppressWarnings("for-rollout:UnusedMethod")
Expand Down Expand Up @@ -59,4 +67,9 @@ public void execute(Task _task) {
task.setDescription("Prints the project's configured version to standard out");
});
}

public Provider<VersionDetails> getVersionDetails() {

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.

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.

return serviceProvider.map(
gitVersionCacheService -> gitVersionCacheService.getVersionDetails(project.getProjectDir(), null));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.io.IOException;

public interface VersionDetails {
String getBranchName() throws IOException;
String getBranchName();

String getGitHashFull() throws IOException;

Expand Down