This message was deleted.
# community-support
s
This message was deleted.
b
I've done things like this before... or at least variants of it.
Copy code
def gitHashMain = new File("${rootProject.rootDir}/.git/refs/heads/main").text
c
e
why not call cli plumbing? should be CC-safe if you use the providers api
c
cli plumbing?
e
as opposed to porcelain
c
I don't remember much about that code, but it uses jgit which is pure java
however gradle itself broke age's ago
a
It would be nice if there was a CC compatible plugin. I use a bit of custom coding to fetch the version via git commands. It's CC safe, so long as you use
providers.exec { ... }
e
I have
Copy code
val gitDescribeResult = providers.exec {
    commandLine("git", "describe", "--always", "--dirty", "--long", "--tags")
    isIgnoreExitValue = true
}
val version = providers.gradleProperty("version").orElse(
    gitDescribeResult.result.map {
        if (it.exitValue != 0) return@map "unknown-SNAPSHOT"
        val describe = gitDescribeResult.standardOutput.asText.get().trim()
        val match = """(.*)-((\d+)-g[0-9a-f]+)(-dirty)?""".toRegex(RegexOption.DOT_MATCHES_ALL).matchEntire(describe)
            ?: return@map describe.removeSuffix("-dirty").ifEmpty { "unknown" } + "-SNAPSHOT"
        val (tag, extra, count, dirty) = match.destructured
        when {
            count.toIntOrNull() != 0 -> "$tag-$extra-SNAPSHOT"
            dirty.isNotEmpty() -> "$tag-SNAPSHOT"
            else -> tag
        }
    }
)
in one of my projects, pretty similar
c
@Adam totally possible mine is, once I unbreak it 😉
🚀 1
It hasn't been updated since gradle 5.1
e
even if you stick with that, you'll probably want to wrap that in a ValueSource for CC compatibility
c
sure, CC didn't exist back in 5.x
like it'll need updating, but it doesn't have the problem of process forking already
c
just because gradle does something unwise...
lol
a
haha fair point
this plugin uses JGit https://github.com/qoomon/gradle-git-versioning-plugin, and it has some quite nice features - it's just not CC compatible
c
I don't think it's going to be hard to at least make mine start again, just bumping to gradle 8.6 made
./gradlew build
work again
but for some reason intellij is treating it like it doesn't recognize the build.gradle.kts source 😕
a
Yeah, I notice that sometimes IntelliJ doesn't like major Gradle updates. Try deleting the
.gradle/
dir.
c
yeah... I did that, might give it another go though... if you clone it is intellij not loving it? moved it with updates here https://github.com/xenoterracide/gradle-semver
nah, that fixed it. but for some reason intellij also requires you to do all such operations when it's closed
now, how did this work, lol, I have working build and all that...
I think I called it
PorcelainGit
not because it used porcelain, but because I was creating
describe
which is considered "porcelain" as a git command (I think/hope)
and at that time, I'd guess that
Git.class
didn't have
describe
it seems to now
v
Be careful
I don't remember much about that code, but it uses jgit which is pure java
is not fully correct. It does one git call to get location of system configuration file. Iirc in a static initializer, so you only hit it if you use a fresh daemon.
👍 1
c
Well, hopefully I'll figure it out by the end of the day... my code currently doesn't do what I intended for it to do (I think), so it needs some serious updating
I'm considering renaming the plugin, but I don't know what to call it yet 😉