Git预提交挂钩无法运行gradle命令

时间:2019-09-20 06:55:17

标签: git gradle android-gradle-plugin

我正在尝试运行以下git pre-commit钩子:

#!/bin/bash

echo "Running git pre-commit hook"

# Format code using KtLint
./gradlew app:ktlintFormat app:ktlint --daemon --stacktrace

RESULT=$?

if [ "$RESULT" = 0 ] ; then
    echo "Ktlint found no problems."
    exit 0
else
    echo 1>&2 "Ktlint found violations it could not fix."
    exit 1
fi

但是它一直在失败。 问题似乎出在我的应用程序build.gradle文件中,在其中我使用gladed/gradle-android-git-version gradle script来应用版本名称和代码。

这是堆栈跟踪

Commit failed with error
0 files committed, 3 files failed to commit: Simplified examination dialog layout and usage.

Running git pre-commit hook
Configuration on demand is an incubating feature.

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/TBS/StudioProjects/SmartGFR/app/build.gradle' line: 37

* What went wrong:
A problem occurred evaluating project ':app'.
> Bare Repository has neither a working tree, nor an index

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.api.GradleScriptException: A problem occurred evaluating project ':app'.

异常指向我的应用程序build.gradle文件中的以下行:

android {
    ...
    defaultConfig {
        ...
        versionName androidGitVersion.name()
...
}

有人知道如何解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

我在本地@bohsen固定了它。

步骤:

  1. 进行修改[https://github.com/gladed/gradle-android-git-version/issues/87#issue-731476471]
  2. 生成本地jar
  3. 导入jar并应用插件
  4. 再次运行该钩子

问题: https://github.com/gladed/gradle-android-git-version/issues/87