I have a gradle project which runs a script, and somewhere in it, I need to clone a git repository. 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.
I need something that will work similar to this SVN code:
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 ). 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!
--Edit--
when i tried to use the grgit as below:
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'.
Could not get unknown property 'org' for root project 'grgit' of type org.gradle.api.Project.
There is a link on the github page of the project to some examples and the API documentation . The following snippet would solve your problem (in this case, it will clone the grgit project to the grgit
directory)
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')
}
}
The documentation states that org.ajoberstar.grgit.auth.hardcoded.allow
is a system property. 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. the problem is solved, but not the bug i had...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.