【发布时间】:2015-07-08 06:17:49
【问题描述】:
我想在编译开始之前从 git repo 中提取更改。 我找到了这个Gradle: how to clone a git repo in a task?,但它克隆了 repo 而不是只获取更改。 如果 git 服务器不在本地网络上或者 repo 很大,这可能会很耗时。
我找不到如何使用 gradle 或 gradle-git plugin 执行 git pull。
【问题讨论】:
我想在编译开始之前从 git repo 中提取更改。 我找到了这个Gradle: how to clone a git repo in a task?,但它克隆了 repo 而不是只获取更改。 如果 git 服务器不在本地网络上或者 repo 很大,这可能会很耗时。
我找不到如何使用 gradle 或 gradle-git plugin 执行 git pull。
【问题讨论】:
您可以创建Exec 任务并运行任何shell/cmd 命令。简单任务不需要额外的插件依赖。
task gitPull(type: Exec) {
description 'Pulls git.'
commandLine "git", "pull"
}
用法:gradlew gitPull
你应该会看到这样的:
gradlew gitPull
Parallel execution is an incubating feature.
:app:gitPull
Already up-to-date.
BUILD SUCCESSFUL
Total time: 9.232 secs
其中Already up-to-date. 是git pull 命令的输出。
【讨论】:
以下 gradle 脚本应该会有所帮助:
import org.ajoberstar.grgit.*
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.ajoberstar:gradle-git:1.1.0'
}
}
task pull << {
def grgit = Grgit.open(dir: project.file('.'))
grgit.pull(rebase: false)
}
【讨论】: