Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle: How to perform git pull through gradle?

I want to pull changes from git repo before compilation begins. I found this Gradle: how to clone a git repo in a task?, but it clones the repo instead of fetching just the changes. This could be time consuming if the git server is not on the local network or if the repo is large.

I could not find how to do git pull using gradle or the gradle-git plugin.

like image 605
Dojo Avatar asked Apr 29 '15 06:04

Dojo


2 Answers

You can create Exec task and run any shell/cmd command. No extra plugin dependency required for simple tasks.

task gitPull(type: Exec) {
    description 'Pulls git.'
    commandLine "git", "pull"
}

Usage: gradlew gitPull

You should see smth like this:

gradlew gitPull 
Parallel execution is an incubating feature.
:app:gitPull 
Already up-to-date.

BUILD SUCCESSFUL

Total time: 9.232 secs

Where Already up-to-date. is the output from git pull command.

like image 70
Sergii Pechenizkyi Avatar answered Oct 12 '22 21:10

Sergii Pechenizkyi


The following gradle script should be helpful:

import org.ajoberstar.grgit.*

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

task pull << {
   def grgit = Grgit.open(dir: project.file('.'))
   grgit.pull(rebase: false)
}
like image 33
Opal Avatar answered Oct 12 '22 21:10

Opal