# Git command in gradle not working

**URL:** <https://discuss.gradle.org/t/git-command-in-gradle-not-working/23592>\
**Category:** Help/Discuss\
**Created:** [August 4, 2017, 9:36am UTC](https://discuss.gradle.org/t/git-command-in-gradle-not-working/23592 "2017-08-04T09:36:39Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![yurii](https://avatars.discourse-cdn.com/v4/letter/y/cdc98d/32.png) [@yurii](https://discuss.gradle.org/u/yurii)\
**Post date:** [August 4, 2017, 9:36am UTC](https://discuss.gradle.org/t/git-command-in-gradle-not-working/23592/1 "2017-08-04T09:36:40Z")

</div>

Hi,  
I have such code and it works ok while I am executing `gradle build` in Intelij Idea and in console but in eclispe it does not produce any output.

Please, can someone explain me how to make horrible eclipse working in normal way??

```gradle
ext{
    buildNumber = ("git rev-parse HEAD").execute().text.trim()
}

println buildNumber

```

---

<div class="post-metadata">

**Author:** ![Schalk\_Cronje](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/schalk_cronje/32/6511_2.png) [@Schalk\_Cronje](https://discuss.gradle.org/u/Schalk_Cronje)\
**Post date:** [August 4, 2017, 11:08pm UTC](https://discuss.gradle.org/t/git-command-in-gradle-not-working/23592/2 "2017-08-04T23:08:16Z")

</div>

If you hard-code the path to `git` i.e.e `/usr/bin/git` does it work then in Eclipse?

---

<div class="post-metadata">

**Author:** ![yurii](https://avatars.discourse-cdn.com/v4/letter/y/cdc98d/32.png) [@yurii](https://discuss.gradle.org/u/yurii)\
**Post date:** [August 7, 2017, 2:45pm UTC](https://discuss.gradle.org/t/git-command-in-gradle-not-working/23592/3 "2017-08-07T14:45:32Z")

</div>

I will try later, but it is not a solution of my problem, because my project must be able to build on different computers with different git installation directories, different OSs and different git versions.

---

<div class="post-metadata">

**Author:** ![Lance](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lance/32/787_2.png) [@Lance](https://discuss.gradle.org/u/Lance)\
**Post date:** [August 7, 2017, 4:56pm UTC](https://discuss.gradle.org/t/git-command-in-gradle-not-working/23592/4 "2017-08-07T16:56:57Z")

</div>

You could use [jgit](https://eclipse.org/jgit/), [grgit](https://github.com/ajoberstar/grgit) or [gradle-git](https://github.com/ajoberstar/gradle-git)

---

<div class="post-metadata">

**Author:** ![Schalk\_Cronje](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/schalk_cronje/32/6511_2.png) [@Schalk\_Cronje](https://discuss.gradle.org/u/Schalk_Cronje)\
**Post date:** [August 8, 2017, 3:45pm UTC](https://discuss.gradle.org/t/git-command-in-gradle-not-working/23592/5 "2017-08-08T15:45:58Z")

</div>

> [@yurii](#):
>
> I will try later, but it is not a solution of my problem, because my project must be able to build on different computers with different git installation directories, different OSs and different git versions

Not it is not, but it will tell you whether Eclipse removes `PATH` from the running environment.

Also I would echo @Lance’s recommendation for using `grgit` instead.

---

<div class="post-metadata">

**Author:** ![yurii](https://avatars.discourse-cdn.com/v4/letter/y/cdc98d/32.png) [@yurii](https://discuss.gradle.org/u/yurii)\
**Post date:** [August 9, 2017, 9:43pm UTC](https://discuss.gradle.org/t/git-command-in-gradle-not-working/23592/6 "2017-08-09T21:43:50Z")

</div>

Thank you for your answers and I am going to try `grgit`!  
But why it have to change my `PATH` from the running environment why can not it work normally?

---

<div class="post-metadata">

**Author:** ![Rob\_Sargent](https://avatars.discourse-cdn.com/v4/letter/r/f475e1/32.png) [@Rob\_Sargent](https://discuss.gradle.org/u/Rob_Sargent)\
**Post date:** [August 10, 2017, 12:08am UTC](https://discuss.gradle.org/t/git-command-in-gradle-not-working/23592/7 "2017-08-10T00:08:11Z")

</div>

Because all IDEs are evil, even IntelliJ.

---

<div class="post-metadata">

**Author:** ![Schalk\_Cronje](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/schalk_cronje/32/6511_2.png) [@Schalk\_Cronje](https://discuss.gradle.org/u/Schalk_Cronje)\
**Post date:** [August 11, 2017, 10:19am UTC](https://discuss.gradle.org/t/git-command-in-gradle-not-working/23592/8 "2017-08-11T10:19:24Z")

</div>

Many tools will do that to isolate the environment from the build process. Even though there can be some frustration in it, as you have discovered in it, there is a lot of good in it.

Accidental pollution from the environment can lead to builds failing on some systems an not others. It can also lead to builds that are not repeatable. Many plugins in Gradle will also isolate the environment to an absolute minimum when running external tools.
