Near1999
Near1999

Reputation: 1607

Gradle versioning with Git

I'm trying to create auto versioning in Gradle with Git, but I got some error when I'm building my app. My os is Windows.

def getVerName = { ->
    try {
        def stdout = new ByteArrayOutputStream()
        exec {
            commandLine "git", "describe", "--long"
            standardOutput = stdout
        }
        def result = stdout.toString()
        result = result.trim()
        return result
    } catch (ignored) {
        return null
    }
}

And here is stack trace of my exception

My GIT path: C:\Program Files\Git\cmd. Setting PATH in local variables doing nothing. From StackTrace you can see that Gradle is looking for git.exe in an app directory. How to change that path?

org.gradle.process.internal.ExecException: A problem occurred starting process 'command 'git''
    at org.gradle.process.internal.DefaultExecHandle.setEndStateInfo(DefaultExecHandle.java:197)
    at org.gradle.process.internal.DefaultExecHandle.failed(DefaultExecHandle.java:327)
    at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:86)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
    at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Error:net.rubygrapefruit.platform.NativeException: Could not start 'git'
    at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:27)
    at net.rubygrapefruit.platform.internal.WindowsProcessLauncher.start(WindowsProcessLauncher.java:22)
    at net.rubygrapefruit.platform.internal.WrapperProcessLauncher.start(WrapperProcessLauncher.java:36)
    at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:68)
    ... 5 more
Error:java.io.IOException: Cannot run program "git" (in directory "C:\Users\Mellony\Resg\app"): CreateProcess error=2, The system cannot find the file specified 
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
    at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:25)
    ... 8 more
Error:java.io.IOException: CreateProcess error=2, The system cannot find the file specified
    at java.lang.ProcessImpl.create(Native Method)
    at java.lang.ProcessImpl.<init>(ProcessImpl.java:386)
    at java.lang.ProcessImpl.start(ProcessImpl.java:137)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
    ... 9 more

Upvotes: 5

Views: 7828

Answers (2)

vkarma
vkarma

Reputation: 11

I had same issue, but at last I found that, the git path is not set in environment variables. I set below paths in PATH variable and it worked for me. C:\Program Files\Git\cmd C:\Program Files\Git\bin\git.exe

Upvotes: 1

RaGe
RaGe

Reputation: 23677

If gradle is having trouble finding the location of git, I would try using the full path for git executable, or alternatively setting the workingDirvalue for Exec.

exec {
  workingDir '../path/to/git/bin'
  commandLine 'cmd', '/c', 'git',...
}

Upvotes: 2

Related Questions