Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute git command from build.gradle?

Tags:

gradle

groovy

Could you guys clarify why

def getBuildSuffix() {
  return 'git rev-list HEAD | wc -l | tr -d " "'.execute().text.trim()
}

returns nothing to me taking into consideration there is data when you run git command from a command line:

prototype (master) $ git rev-list HEAD | wc -l | tr -d " "
72

May be I'm just executing a git command from my build.gradle in a wrong way?

like image 209
Eugene Avatar asked Oct 29 '14 14:10

Eugene


People also ask

How do I run a build in Gradle?

From the main menu, select Run | Edit Configurations to open the run/debug configuration for your project. icon. In the list that opens, select Run Gradle task. In the Select Gradle Task dialog, specify the project and the task that you want to execute before launching the project.

How do I run a Gradle command?

Press ⌃⌃ (macOS), or Ctrl+Ctrl (Windows/Linux), type "gradle" followed by the gradle task name or names. We can, of course, run Gradle commands from the terminal window inside IntelliJ IDEA. Open this with ⌥F12 (macOS), or Alt+F12 (Windows/Linux).

What can you do with build Gradle?

Gradle makes it easy to build common types of project — say Java libraries — by adding a layer of conventions and prebuilt functionality through plugins. You can even create and publish custom plugins to encapsulate your own conventions and build functionality.

What is Gradle Git?

gradle-git is a set of Gradle plugins: org.


1 Answers

Pipe is a shell feature so you need to go like:

['sh', '-c', 'git rev-list HEAD | wc -l | tr -d " "'].execute().text.trim()
like image 86
topr Avatar answered Oct 05 '22 11:10

topr