Skip to content

Commit cbaf955

Browse files
committed
Allow lenient GitVersion creation (until 3.0)
Subprojects that do not need to use their own version will use the root project's version. For now this is handled by catching failure of the Git Version creation on the subproject, and trying to create one using the root project instead. Management of Git Version will be refined in GradleUtils 3.0. Consider the usage of it an incubating feature until then.
1 parent 9160c0c commit cbaf955

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/main/groovy/net/minecraftforge/gradleutils/gitversion/GitVersionExtension.groovy

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ class GitVersionExtension {
5757
@PackageScope @Lazy GitVersion versionInternal = {
5858
GitVersion.disableSystemConfig()
5959

60-
var builder = GitVersion.builder().project(this.layout.projectDirectory.asFile)
60+
var projectDir = this.layout.projectDirectory.asFile
61+
var builder = GitVersion.builder().project(projectDir)
62+
var gitversion = this.tryBuild(builder)
63+
return gitversion ?: tryBuild(builder.project(GitVersion.findGitRoot(projectDir)))
64+
65+
/*
6166
try {
6267
return builder.build().tap { it.info }
6368
} catch (GitVersionException ignored) {
@@ -67,8 +72,20 @@ class GitVersionExtension {
6772
this.project.logger.error 'ERROR: Git Version is misconfigured and cannot be used, likely due to incorrect paths being set. This is an unrecoverable problem and needs to be addressed in the config file. Ensure that the correct subprojects and paths are declared in the config file'
6873
throw e
6974
}
75+
*/
7076
}()
7177

78+
// TODO [GitVersion][Gradle] Handle this better in GU3.0
79+
private static @Nullable GitVersion tryBuild(GitVersion.Builder builder) {
80+
try {
81+
builder.build().tap { info }
82+
} catch (GitVersionException ignored) {
83+
builder.strict(false).build()
84+
} catch (IllegalArgumentException ignored) {
85+
null
86+
}
87+
}
88+
7289
// TODO [GradleUtils][3.0] Make private
7390
private static boolean deprecationWarning
7491
@Deprecated(forRemoval = true)

0 commit comments

Comments
 (0)