简体   繁体   English

使用Grgit在我的gradle上克隆git存储库

[英]clone git repository on my gradle using Grgit

I have a gradle project which runs a script, and somewhere in it, I need to clone a git repository. 我有一个gradle项目,它运行一个脚本,并且在其中某个地方,我需要克隆一个git存储库。 I had it running before with svn, but I change our company SCM to gitlab, and I need to change the code so it'll now clone the repo from git. 我之前曾用svn运行它,但我将公司SCM更改为gitlab,并且我需要更改代码,因此现在可以从git复制存储库。

I need something that will work similar to this SVN code: 我需要一些类似于此SVN代码的东西:

task exportLibs(type: SvnExport) {
  svnUrl = "http://<svn-url>"
  targetDir = "<target-dir-to-download-files>"
}

So I read about Grgit, but there was not a single example online, how to do a simple git clone (only this link http://ajoberstar.org/grgit/docs/groovydoc/org/ajoberstar/grgit/operation/CloneOp.html ). 因此,我阅读了有关Grgit的信息,但在线上没有一个示例,介绍如何执行简单的git克隆(仅此链接http://ajoberstar.org/grgit/docs/groovydoc/org/ajoberstar/grgit/operation/CloneOp。 html )。 If there is someone who can help me walkthrough this problem or maybe produced me to his grgit project so i will learn from it, it'll be awesome! 如果有人可以帮助我解决这个问题,或者让我参加他的grgit项目,以便我从中学习,那就太好了!

--Edit-- - 编辑 -

when i tried to use the grgit as below: 当我尝试如下使用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'
}

i've use this properties to initial it, and i got the following error: 我已经使用此属性对其进行了初始化,但出现以下错误:

A problem occurred evaluating root project 'grgit'. 评估根项目'grgit'时发生问题。

Could not get unknown property 'org' for root project 'grgit' of type org.gradle.api.Project. 无法获得类型为org.gradle.api.Project的根项目“ grgit”的未知属性“ org”。

There is a link on the github page of the project to some examples and the API documentation . 该项目的github页面上有一些示例和API文档的链接 The following snippet would solve your problem (in this case, it will clone the grgit project to the grgit directory) 以下代码片段将解决您的问题(在这种情况下,它将把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')
    }
}

Answer to the edited question 回答已编辑的问题

The documentation states that org.ajoberstar.grgit.auth.hardcoded.allow is a system property. 文档指出org.ajoberstar.grgit.auth.hardcoded.allow是系统属性。 Your assignment is not a valid way to set system properties, see the answer to this question for examples on setting system properties in groovy. 你的任务是不设置系统属性,一看便知,以有效的方式这个问题上的常规设置系统属性的例子。

my code probably had some special imports in it, cause a the end the only clone that i could have done is shell exec. 我的代码中可能包含一些特殊的导入,导致最后我唯一可以做的克隆就是shell exec。 the problem is solved, but not the bug i had... 问题已解决,但不是我遇到的错误...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM