Skip to content

Apache Lucene open-source search software

Do not try to fail .git folder provider, fail at runtime if it's not available (#14951)

Dawid Weiss0016aa412a7a
diff --git a/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/gitinfo/GitInfoPlugin.java b/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/gitinfo/GitInfoPlugin.java
index 1d66a83eff0..a7f64593d77 100644
--- a/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/gitinfo/GitInfoPlugin.java
+++ b/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/gitinfo/GitInfoPlugin.java
@@ -53,9 +53,9 @@ public class GitInfoPlugin extends LuceneGradlePlugin {
project.getRootProject().getLayout().getProjectDirectory();
Path gitLocation = projectDirectory.getAsFile().toPath().resolve(".git");
if (!Files.exists(gitLocation)) {
- throw new GradleException(
- "Can't locate .git (probably not a git clone?): "
- + gitLocation.toAbsolutePath());
+ // don't return anything from the provider if we can't locate the .git
+ // folder. This will result in the property returning false from isPresent.
+ return null;
}
if (Files.isDirectory(gitLocation)) {
diff --git a/lucene/distribution/build.gradle b/lucene/distribution/build.gradle
index e1035278dbb..c484e54390e 100644
--- a/lucene/distribution/build.gradle
+++ b/lucene/distribution/build.gradle
@@ -53,7 +53,13 @@ tasks.register("assembleSourceTgz", QuietExec, {
workingDir = project.rootDir
// An explicit GIT_DIR to prevent .git upward scanning if something goes wrong.
- environment("GIT_DIR", "${gitInfoExt.getDotGitDir().get().asFile.toString()}")
+ if (gitInfoExt.getDotGitDir().isPresent()) {
+ environment("GIT_DIR", gitInfoExt.getDotGitDir().get().asFile.toString())
+ } else {
+ doFirst {
+ throw new GradleException("Can't assemble source tgz without a full git clone.")
+ }
+ }
args += [
"archive",