`generateGitProperties` fails to resolve .git dir on 2.5.0
After picking up 2.5.0 generateGitProperties task fails with the following cause:
Caused by: org.gradle.api.GradleException: No Git repository found. Ensure the gitProperties.dotGitDirectory property points to the correct .git directory.
at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:62)
at org.gradle.internal.classpath.intercept.DefaultCallSiteDecorator$DecoratingCallSite.lambda$callConstructor$2(DefaultCallSiteDecorator.java:248)
at org.gradle.internal.instrumentation.api.groovybytecode.InvocationImpl.callNext(InvocationImpl.java:63)
at org.gradle.internal.classpath.intercept.DefaultCallSiteDecorator$1.intercept(DefaultCallSiteDecorator.java:88)
at org.gradle.internal.classpath.intercept.DefaultCallSiteDecorator$DecoratingCallSite.callConstructor(DefaultCallSiteDecorator.java:247)
at com.gorylenko.GenerateGitPropertiesTask.generate(GenerateGitPropertiesTask.groovy:114)
...
This is on a multi-project build, and after taking a very quick look at https://github.com/n0mer/gradle-git-properties/commit/84306004450b99aab3857f05c8f465c49bb43de0 I suspect those changes don't take such setup into account.
I had the same issue, but setting following config:
gitProperties {
dotGitDirectory = project.rootProject.layout.projectDirectory.dir(".git")
}
Solved the issue for me
That's certainly possible, but rather than adding workarounds IMO it's wiser to skip the upgrade to 2.5.0 altogether and instead wait for the release that will fix this regression.
I can see at https://github.com/n0mer/gradle-git-properties/pull/235
The git directory has to be set explicitly with dotGitDirectory property.
I think that this either should be changed, or a note about multi-project build should be added to https://github.com/n0mer/gradle-git-properties/blob/master/README.md?plain=1#L142
This workaround helped for our composite build project
fun findGitDirectory(startDir: File): File? {
var currentDir: File? = startDir
while (currentDir != null && !File(currentDir, ".git").exists()) {
currentDir = currentDir.parentFile
}
return currentDir?.let { File(it, ".git") }
}
gitProperties {
val gitDir = findGitDirectory(project.projectDir)
if (gitDir != null) {
dotGitDirectory.set(gitDir)
} else {
throw GradleException("Could not find .git directory")
}
}
build.gradle.kts multi-project workaround:
gitProperties {
dotGitDirectory.set(file("${rootProject.rootDir}/.git"))
}
in combination with worktrees the workaround from https://github.com/n0mer/gradle-git-properties/issues/14 does not work anymore with this change
We have the same problem and don't use a multi-module build. We simply use a setup generated by https://start.spring.io.
As for 99.9% of all projects .git is the correct Git folder. I really don't wanna setup the property for all the 10 services we have, this should rather be a working default. Any ETA?
With Gradle 8.13 you can write
gitProperties {
dotGitDirectory = layout.settingsDirectory.dir(".git")
}
This should be compatible with the configuration cache, so maybe it can be incorporated as a default for the plugin (provided Gradle version is >= 8.13)?
So much for proper semantic versioning this was a breaking change. As others have already stated this simply should be the default or if it wasn't possible, this should have been properly referenced as a breaking change and semantic version updated accordingly.
Since this breaks multi-project builds (which are very common) would it make sense to set this as the default which I think would work for the majority of the users?
gitProperties.dotGitDirectory = project.rootProject.layout.projectDirectory.dir('.git')
Edit: well maybe it should also handle worktrees: https://github.com/n0mer/gradle-git-properties/issues/242#issuecomment-2756001703
This breaks the configuration cache again due to the usage of rootProject. See https://github.com/n0mer/gradle-git-properties/issues/240#issuecomment-2732069210 for a solution which is compatible with the configuration cache.
Any progress or eta here? It fails most of our pipelines still
Any progress or eta here? It fails most of our pipelines still
@cmdjulian I guess it's "resolved" by this section in the README:
gitProperties {
// if .git directory is on the same level as the root project
dotGitDirectory = project.rootProject.layout.projectDirectory.dir(".git")
// if .git directory is in a different location
dotGitDirectory = "${project.rootDir}/../somefolder/.git"
}
BTW, I hate these backward incompatible changes in non-major version upgrades. @tha2015 next time, could you please raise the major version for such changes?
Why am I as a user are forced to set those settings in the first place though?
I'm not too deep into Gradle plugin development, but can't this be set as a default within the plugin itself? This is not convenient for the user at all.
I don't want to maintain these settings for all of our projects now
I don't want to maintain these settings for all of our projects now
There should be no need to manually configure the defaults. When you set up your git repository you also don't have to specify manually that it should use the .git folder. The plugin should have reasonable defaults so it works out of box with zero configuration, which would also maintain backwards compatibility and avoid forcing the whole userbase to add completely unnecessary and avoidable configuration options. We are also ignoring this update, it's not worth the hassle.
Please try v.2.5.2 to see if the issue is fixed. Thanks.
@tha2015 didn't work for our project after upgrading to 2.5.2. This workaround still helps https://github.com/n0mer/gradle-git-properties/issues/240#issuecomment-2710689037
Reopening for fixing again
please check if issue still exists with version 2.5.3
I get the same issue with jdk23, gradle 8.14.2 and the git-props plugin version 2.5.3.
gitProperties { extProperty = 'gitProps' dotGitDirectory = project.rootProject.layout.projectDirectory.dir(".git") } generateGitProperties.outputs.upToDateWhen { false }
Task :generateGitProperties FAILED [Incubating] Problems report is available at: ****/build/reports/problems/problems-report.html FAILURE: Build failed with an exception.
- What went wrong: Execution failed for task ':generateGitProperties'.
No Git repository found. Ensure the gitProperties.dotGitDirectory property points to the correct .git directory.
FYI I was stuck for a while with this error message because I got confused by a different issue: if you're in a monorepo where the settings.gradle or rootProject are not in the git root of the repo, you need something like
gitProperties {
dotGitDirectory = layout.settingsDirectory.dir("../.git")
}
(notice the ../)