Gradle:如何在任务中克隆 git repo?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13719676/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Gradle: how to clone a git repo in a task?
提问by Sergey Weiss
Suppose I have a gradle build script and want to write a task to clone a remote git repository. How do I do that?
假设我有一个 gradle 构建脚本并且想要编写一个任务来克隆远程 git 存储库。我怎么做?
回答by Sergey Weiss
The cloning can be done using the Gradle-git plugin. To use the plugin you should download it first:
克隆可以使用Gradle-git 插件完成。要使用该插件,您应该先下载它:
buildscript {
repositories { mavenCentral() }
dependencies { classpath 'org.ajoberstar:gradle-git:0.2.3' }
}
Then write a task like this one:
然后写一个这样的任务:
import org.ajoberstar.gradle.git.tasks.*
task cloneGitRepo(type: GitClone) {
def destination = file("destination_folder")
uri = "your_git_repo_uri"
destinationPath = destination
bare = false
enabled = !destination.exists() //to clone only once
}
回答by ajoberstar
With newer versions of gradle-git(0.7.0 and up), you would create the task like this:
使用较新版本的gradle-git(0.7.0 及更高版本),您将创建这样的任务:
import org.ajoberstar.grgit.*
task clone << {
Grgit.clone(dir: file('build/repo'), uri: '[email protected]:user/repo.git')
}
回答by Chamila Chulatunga
There is a Git plugin - docs here: Gradle-git. The plugin has a clone method: GitClone
这里有一个 Git 插件 - 文档:Gradle-git。该插件有一个克隆方法:GitClone
Probably something along the lines of:
大概是这样的:
GitClone clone = new GitClone();
clone.setUri("http://remote.repository/");
clone.setDestinationPath("//local/path");
clone.setBare(false);
clone.cloneRepo();
回答by mpierce
The aforementioned Gradle-git plugin seems to have moved on from providing straightforward "clone this repo to that directory" functionality, so I wrote a simple task that does just this:
前面提到的 Gradle-git 插件似乎已经不再提供简单的“将这个 repo 克隆到那个目录”的功能,所以我写了一个简单的任务来做到这一点:
回答by CharlesB
The Gradle-gitplugin has a GitClone taskthat should help. I can't help you on how to use it since I don't know Gradle.
的摇篮- git的插件有一个GitClone任务,应该帮助。我无法帮助您了解如何使用它,因为我不了解 Gradle。