【问题标题】:Sherter Gradle plugin for pre-commit用于预提交的 Sherter Gradle 插件
【发布时间】:2019-03-07 23:54:55
【问题描述】:

我正在尝试为代码样式添加 sherter gradle 插件。我想在预提交脚本文件中运行这个插件。

我在 gradle 中添加了 sherter,

repositories {
   jcenter()
   maven { url "https://plugins.gradle.org/m2/" }
}

dependencies {
   classpath 'gradle.plugin.com.github.sherter.google-java-format:google-java-format-gradle-plugin:0.6'
}

apply plugin: 'com.github.sherter.google-java-format'

我的预提交文件位于名为“scripts”的目录中。如果我添加了这样的行,在预提交文件中

./gradlew verifyGJF

它在那里失败了。当我转到项目根目录并运行相同的命令时。为什么会这样?我是否必须链接到 gradle 文件。

注意:Gradle 文件是可执行的,它在项目根目录中运行良好,但从预提交文件甚至在终端中,如果我转到“脚本”文件夹,verifyGJF 没有运行。

【问题讨论】:

    标签: android gradle pre-commit google-java-format


    【解决方案1】:

    发生这种情况是因为 gradlew 实际上是项目目录根目录下的一个脚本(请参阅下面的文件夹层次结构)。

    gradlew
    /scripts
       pre-commit-script
    /src
    

    从您的pre-commit-script 文件中运行./gradlew {task} 会指示它在同一目录(这里是/scripts)中查找gradlew

    如果您尝试从子目录中调用gradlew,则需要使用相对路径访问它:../gradlew verifyGJF

    希望对你有所帮助?

    【讨论】:

      猜你喜欢
      • 2016-01-21
      • 2015-12-03
      • 2012-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-22
      • 1970-01-01
      相关资源
      最近更新 更多