摇篮:如何克隆在任务的混帐回购协议?(Gradle: how to clone a git repo

2019-07-04 13:39发布

假设我有一个gradle这个构建脚本,并希望写一个任务来克隆一个远程的Git仓库。 我怎么做?

Answer 1:

克隆可以用做摇篮- git的插件 。 要使用该插件,你应该首先下载:

buildscript {
  repositories { mavenCentral() }
  dependencies { classpath 'org.ajoberstar:gradle-git:0.2.3' }
}

然后写这样一个任务:

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
}


Answer 2:

随着新版本的gradle产出-git的 (0.7.0及以上),你可以创建这样的任务:

import org.ajoberstar.grgit.*

task clone << {
  Grgit.clone(dir: file('build/repo'), uri: 'git@github.com:user/repo.git')
}


Answer 3:

有一个Git插件-文档浏览: 摇篮,git的 。 该插件有一个克隆方法: GitClone

也许东西沿着线:

GitClone clone = new GitClone();
clone.setUri("http://remote.repository/");
clone.setDestinationPath("//local/path");
clone.setBare(false);
clone.cloneRepo();


Answer 4:

上述摇篮 - git的插件似乎已经从简单的提供“克隆此回购该目录”功能的移动,所以我写了一个简单的任务,不只是这一点:

https://github.com/palominolabs/gradle-git-clone-task



Answer 5:

的摇篮- git的插件有一个GitClone任务 ,应该帮助。 我不能帮你如何使用它,因为我不知道摇篮。



文章来源: Gradle: how to clone a git repo in a task?
标签: git gradle