Gracefully handle detached HEAD in branch version check
Previously, the `CheckExpectedBranchVersionPlugin` would crash the Gradle
configuration phase if the project was in a detached HEAD state or not
in a Git repository, e.g., downloaded as a ZIP.
This commit refactors the plugin to be lazy and adopts several Gradle best
practices:
- Prevents build crashes on Git failures by gracefully catching non-zero
exit codes, e.g., when checked out in a detached HEAD state.
- Moves the branch validation out of the task's main execution action
and into an `onlyIf` predicate, allowing Gradle to skip the task
entirely instead of executing an early return. This makes the skip
outcome and reason visible in a Build Scan, rather than making it
appear as if it executed.
- Defers the Git `exec` call to the execution phase using a lazy provider.
- Makes the task configuration cache compatible by avoiding illegal
`Project` access inside the execution-time `onlyIf` closure.
- Improves user-facing logs and adds actionable bypass instructions when
the project version doesn't match the branch version.
Signed-off-by: Eric Haag <ehaag@gradle.com>
@ -44,21 +49,53 @@ public class CheckExpectedBranchVersionPlugin implements Plugin<Project> {
@@ -44,21 +49,53 @@ public class CheckExpectedBranchVersionPlugin implements Plugin<Project> {
logger.info("Git branch name is '{}'.",branchName);
returnbranchName;
});
}
@CacheableTask
@ -77,15 +114,10 @@ public class CheckExpectedBranchVersionPlugin implements Plugin<Project> {
@@ -77,15 +114,10 @@ public class CheckExpectedBranchVersionPlugin implements Plugin<Project> {