Skip to content

Commit 072bb9d

Browse files
committed
PropertyExposingClosure returns empty properties when output file doesn't exist yet
During configuration phase, the git.properties file hasn't been generated yet. Using getOrNull() instead of eager get() prevents exceptions and returns empty properties until the file is available after task execution.
1 parent 398a74b commit 072bb9d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/main/java/io/github/git/commit/id/gradle/plugin/GitCommitIdPlugin.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
package io.github.git.commit.id.gradle.plugin;
1919

2020
import groovy.lang.Closure;
21-
import java.util.Arrays;
21+
import java.io.File;
2222
import java.util.Map;
2323
import java.util.Properties;
2424
import org.gradle.api.Plugin;
@@ -94,9 +94,15 @@ public String toString() {
9494

9595
private Properties getProps() {
9696
try {
97+
File outputFile = task.getOutput().getAsFile().getOrNull();
98+
if (outputFile == null || !outputFile.exists()) {
99+
// Return empty properties during configuration phase
100+
// when file hasn't been generated yet
101+
return new Properties();
102+
}
97103
final Properties p = GenericFileManager.readPropertiesAsUtf8(
98104
task.getGitCommitIdPluginOutputSettingsExtension().getOutputFormat().get(),
99-
task.getOutput().getAsFile().get()
105+
outputFile
100106
);
101107
return p;
102108
} catch (GitCommitIdExecutionException e) {

0 commit comments

Comments
 (0)