Gradle:如何执行git拉通gradle?
Gradle: How to perform git pull through gradle?
我想在编译开始之前从 git 存储库中提取更改。
我找到了这个 Gradle: how to clone a git repo in a task?,但它克隆了存储库而不是只获取更改。
如果 git 服务器不在本地网络上或者存储库很大,这可能会很耗时。
我找不到如何使用 gradle 或 gradle-git plugin 来完成 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)
}
您可以创建 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
命令的输出。
我想在编译开始之前从 git 存储库中提取更改。 我找到了这个 Gradle: how to clone a git repo in a task?,但它克隆了存储库而不是只获取更改。 如果 git 服务器不在本地网络上或者存储库很大,这可能会很耗时。
我找不到如何使用 gradle 或 gradle-git plugin 来完成 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)
}
您可以创建 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
命令的输出。