Gradle: How to execute git extrude through gradle?

I want to extract changes from git repo before starting compilation. I found this Gradle: how to clone a git repository in a task? but he clones the repo instead of only pulling the changes. This can take a long time if the git server is not on the local network or if the repository is large.

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

+6
source share
2 answers

You can create an Exec task and run any shell / cmd command. Simple tasks do not require an additional plugin dependency.

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

Usage: gradlew gitPull

You should see smth as follows:

 gradlew gitPull Parallel execution is an incubating feature. :app:gitPull Already up-to-date. BUILD SUCCESSFUL Total time: 9.232 secs 

Where is Already up-to-date. is the result of the git pull command.

+7
source

The following gradle script should be useful:

 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) } 
+4
source

Source: https://habr.com/ru/post/986201/


All Articles