[英]clone git repository on my gradle using Grgit
我有一个gradle项目,它运行一个脚本,并且在其中某个地方,我需要克隆一个git存储库。 我之前曾用svn运行它,但我将公司SCM更改为gitlab,并且我需要更改代码,因此现在可以从git复制存储库。
我需要一些类似于此SVN代码的东西:
task exportLibs(type: SvnExport) {
svnUrl = "http://<svn-url>"
targetDir = "<target-dir-to-download-files>"
}
因此,我阅读了有关Grgit的信息,但在线上没有一个示例,介绍如何执行简单的git克隆(仅此链接http://ajoberstar.org/grgit/docs/groovydoc/org/ajoberstar/grgit/operation/CloneOp。 html )。 如果有人可以帮助我解决这个问题,或者让我参加他的grgit项目,以便我从中学习,那就太好了!
- 编辑 -
当我尝试如下使用grgit时:
group 'test'
version '1.0-SNAPSHOT'
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.ajoberstar:gradle-git:1.7.2"
}
}
apply plugin: 'java'
apply plugin: 'org.ajoberstar.grgit'
org.ajoberstar.grgit.auth.hardcoded.allow=true
task pullFromGit{
doLast {
//grgit.pull()
}
}
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
}
我已经使用此属性对其进行了初始化,但出现以下错误:
评估根项目'grgit'时发生问题。
无法获得类型为org.gradle.api.Project的根项目“ grgit”的未知属性“ org”。
该项目的github页面上有一些示例和API文档的链接 。 以下代码片段将解决您的问题(在这种情况下,它将把grgit项目克隆到grgit
目录)
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.ajoberstar:grgit:1.7.2'
}
}
task hello {
doLast {
org.ajoberstar.grgit.Grgit.clone(dir: 'grgit', uri: 'https://github.com/ajoberstar/grgit.git')
}
}
该文档指出org.ajoberstar.grgit.auth.hardcoded.allow
是系统属性。 你的任务是不设置系统属性,一看便知,以有效的方式这个问题上的常规设置系统属性的例子。
我的代码中可能包含一些特殊的导入,导致最后我唯一可以做的克隆就是shell exec。 问题已解决,但不是我遇到的错误...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.