Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle: how to clone a git repo in a task?

Tags:

Suppose I have a gradle build script and want to write a task to clone a remote git repository. How do I do that?

like image 436
Sergey Weiss Avatar asked Dec 05 '12 09:12

Sergey Weiss


People also ask

How do I clone a project from a branch?

You can clone a specific branch from a Git repository using the git clone –single-branch –branch command. This command retrieves all the files and metadata associated with one branch. To retrieve other branches, you'll need to fetch them later on.


1 Answers

The cloning can be done using the Gradle-git plugin. To use the plugin you should download it first:

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 } 
like image 156
Sergey Weiss Avatar answered Sep 21 '22 09:09

Sergey Weiss