Cannot execute Git commands from Gradle build script on Windows 10 - windows

I have recently forked and cloned a repositroy from GitHub that uses Gradle, but I am unable to execute any Gradle tasks.
It fails on:
def process = 'git rev-parse --short HEAD'.execute()
with:
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\Users\Joseph\Desktop\Minecraft\ObsidianSuite\ForgeGradle\ForgeGradle\build.gradle' line: 286
* What went wrong:
A problem occurred evaluating root project 'ForgeGradle'.
> Cannot run program "git": CreateProcess error=2, The system cannot find the file specified
I am running Windows 10, and have Git working with MinGW. I have set the path variable to include (C:\Program Files\Git\cmd) such that I can run Git from command prompt. The Git command that is called by the build.gradle file executes fine if I run it from the command line, it is just not working when run through the Gradle wrapper.
Any help or advice would be much appreciated; I am able to answer any questions that might help work out what the issue is. Thanks.
EDIT: I normally use Git by running git-bash in the relevant folder rather than git from command prompt.

I have found a solution, it doesn't provide an answer to why it wasn't working originally, but gives a work around.
I followed this answer to install GitHub for Windows and changed the old Git path variable to the one the tutorial suggested. Although I don't want to use the GitHub software (I like doing everything via git-bash), at least Gradle is happy with it now.

Not sure if this is the same problem.
I am using Android studio here. When gradlew build is executed, def process = 'git rev-parse --short HEAD'.execute() returns empty, but there is no problem in local execution.
Solution:
The solution is: modify the jdk path used by gradlew, use java jdk. (Do not use the sdk that comes with android studio)
Screenshot:
enter image description here

Please, don't call executables from Java/Groovy/Gradle/etc. There are many java/groovy libraries to deal with Git repositories, including Gradle plugins

Related

Gradle init isn't interactive

I am using gradle through command line for the first time. I am running the latest version of Ubuntu. My professor's instructions indicate that upon typing "gradle init" I should be prompted to say what type of project it is as well as the language, etc. Mine simply skips all of that and says "build successful" afterwards, my professors' file ends up with the proper directory structure and mine only has the basic root folders. From the quick searches I've done, I see that there is a difference between interactive and non-interactive responses, but I can't find anything regarding how to make it interactive.
My issue was I installed gradle with sudo apt install gradle which installs a very old version. Instead you can install sdk and then run sdk install gradle
If it says something along the lines of:
> Task :init SKIPPED
The build file 'build.gradle' already exists. Skipping build initialization.
BUILD SUCCESSFUL in 5s
Then it means you already have a Gradle build structure present. In order to initialize a new one, the directory you run it in must be empty.
I had this problem, too. Seems to be a bug.
You can tell gradle non-interactively what type to create, for example:
gradle init --type java-library
Other build types

Git post-checkout hook on windows

I installed git 2.28.0 on windows.
In fact, i can't find post-checkout.sample hook in the hooks repository under /.git repository.
Is post-checkout.sample hook supported on windows ?
When i installed the same version of git on linux i found the post-checkout.sample hook.
I even tried with the git 2.23.0 version and i had the same problem.
I tried to create post-checkout that print a simple message "hello". But it doesn't work. However when I copied this file in pre-commit it works.
Any suggestions?
It seems that it doesn't work on an empty repository.
I just committed a file in my repository and when i excute git checkout -b new_branch, the post-checkout hook worked.
I never saw a post-checkout.sample in mingw64/share/git-core/templates/hooks/ of a Git For Windows distribution.
But that hook should work, provided you make it:
a file named "post-checkout"
a bash script (see an example here)
in your repo/.git/hooks folder
There was actually a proposal (RFC) for a post-checkout.sample in 2009, but it was not picked up at the time.
The question was asked (also in 2009):
I also noticed that the
post-checkout sample does not exist when I init a new archive. Is this a
bug?
No, it's security.
Hooks are executable files and shouldn't blindly be
copied around for security reasons.

Unable to retrieve git submodule in jenkins with git-client plugin

I'm trying to have Jenkins retrieve the submodules of a repository, but I cannot get it to work. I've looked around on the internet for a solution, but most problems there center around authentication, which is not the issue in this case. From what I've been able to gather from the error message, the issue seems to be related to the way the git-client plugin handles reponses from the command-line tools.
As we had Git for Windows version 2.6.0 installed and the Jenkins Git-client plugin 'officially' supports version 2.5.0, I also tried uninstalling version 2.6.0 and installed version 2.5.0, but that made no difference.
Does anyone here have any experience with this problem or a possible solution?
The error is:
FATAL: Command "c:\Program Files\Git\bin\git.exe submodule update" returned status code 1:
stdout:
stderr: Cloning into 'mysubmodule'...
error: cannot spawn echo : No such file or directory
bash: /dev/tty: No such device or address
error: failed to execute prompt script (exit code 1)
fatal: could not read Username for 'http://somerepo': No error
Clone of 'http://somerepo/scm/bf/mysubmodule.git' into submodule path 'mysubmodule' failed
I have experienced the very same error, with same version of Git and Jenkins Git-client plugin.
It appears that this could be a combination of a bug and a misconfiguration of the submodule(s) in the .gitmodules file of the main repository. And the error message is definitely not as helpful as it could be!
In my case the .gitmodules file in the main repository contained the absolute url path to the submodule. This caused Jenkins to not be able to authenticate properly for the submodule. Changing the submodule path to be relative (../mysub.git) fixed it for me.
This helped me quite a lot:
https://issues.jenkins-ci.org/browse/JENKINS-31244
I hope you find this helpful.

Git bundled into Cocoa app cannot find helpers in bundle

Context:
I have a Mac app. I want to include Git in this app because some functions of my app use Git and I don't want the user to have to install it on his machine.
I have downloaded Git from source. I edited the Makefile to declare these two lines:
NO_GETTEXT="yesPlease"
CURLDIR=/usr/local
The first line tells the build process to skip localizing and just use English.
The second line declares the path to where libcurl is installed. I downloaded libcurl_devel and built it from source. This is required to enable Git to pull/push from http and https repos.
Git builds successfully. I then copy all of the resulting files into my app's bundle. I'm using NSTask to run Git and attempt to pull an https://-based repo.
The Problem:
The error I get is:
fatal: Unable to find remote helper for 'https'
I googled this, and everyone said that as long as I had libcurl installed when I built Git, Git would work with HTTP and HTTPS addresses. And, in fact, if I run the installed Git from the command line, it does!
What I Need:
So, I must be missing a path setting or an environment variable or SOMETHING that tells Git where to find those remote helpers. They ARE in my app bundle; the screenshot below shows them:
So: what the hell do I need to set in order to resolve this problem when I run Git from within my application bundle?
Unbelievable. I've been trying to fix this for 8+ hours and five minutes after I finally break down and post this question, I figure it out:
Git has an option called --exec-path. I had been passing this argument to the NSTask like this (Where APP BUNDLE is replaced by the path to the application bundle on the user's machine):
--exec-path=[APP BUNDLE]/git/bin
Since bin was the folder where the Git binary was located, I figured that was the appropriate path. However, if I do this:
--exec-path=[APP BUNDLE]/git/libexec/git-core
It works.

SVN error while taking checkout using script

I am getting below error when taking checkout from svn using a script.
**[Test] $ /bin/sh -xe /tmp/hudson8576425899836211909.sh
+ sh /cvsrx/rxapp/build_dir/Jenkins_Scripts/test.sh
Could not load program svn:
Could not load module /opt/freeware/lib/libssl.so.
Dependent module /usr/lib/libcrypto.a(libcrypto.so.1.0.1) could not be loaded.
Member libcrypto.so.1.0.1 is not found in archive
Could not load module svn.
Dependent module /opt/freeware/lib/libssl.so could not be loaded.
Could not load module .
Build step 'Execute shell' marked build as failure
Finished: FAILURE**
In test.sh I have written just one line svn co /path to svn branch/
I am in middle of some test so please don't ask why am not using jenkins in build svn plugin.
here,I am able to take checkout on command prompt using svn co /path to svn branch/
But not if I write this command line in script and run in execute shell of jenkins.
Any help please ?
Am using jenkins on AIX 7 platform.
I had softlinks from /usr/bin/svn to /opt/freeware/bin/svn.SVN installed at /opt/freeware/bin/svn ..... By default when i do which svn its showing /usr/bin/svnBut When i deleted those softlinks and exported path,Jenkins didnt recognize SVN at all.And which svn command doesnot show any svn installed . PFB logs of jenkins :
`
/bin/sh -xe /tmp/hudson5607872610124977868.sh
+ export PATH=/opt/freeware/bin/svn/:/opt/freeware/bin/svnversion:/opt/freeware/bin/svn:/opt/freeware/bin/svnversion/:/usr/java5/lib:/opt/freeware/bin/svnversion/bin:/usr/local/bin:/usr/bin:/usr/X11R7/bin:/bin:/usr/games:/opt/gnome/bin:/opt/kde3/bin:/usr/lib/mit/bin:/sbin:/
+ echo /opt/freeware/bin/svn/:/opt/freeware/bin/svnversion:/opt/freeware/bin/svn:/opt/freeware/bin/svnversion/:/usr/java5/lib:/opt/freeware/bin/svnversion/bin:/usr/local/bin:/usr/bin:/usr/X11R7/bin:/bin:/usr/games:/opt/gnome/bin:/opt/kde3/bin:/usr/lib/mit/bin:/sbin:/opt/freeware/bin/svn/:/opt/freeware/bin/svnversion:/opt/freeware/bin/svn:/opt/freeware/bin/svnversion/:/usr/java5/lib:/opt/freeware/bin/svnversion/bin:/usr/local/bin:/usr/bin:/usr/X11R7/bin:/bin:/usr/games:/opt/gnome/bin:/opt/kde3/bin:/usr/lib/mit/bin:/sbin
+ cd /usr/local/apps/Jenkins_new/scripts
+ ./test.sh
Could not load program /opt/freeware/bin/svn:
Could not load module /opt/freeware/lib/libssl.so.
Dependent module /usr/lib/libcrypto.a(libcrypto.so.1.0.1) could not be loaded.
Member libcrypto.so.1.0.1 is not found in archive
Could not load module svn.
Dependent module /opt/freeware/lib/libssl.so could not be loaded.
Could not load module .
./test.sh[3]: svn: not found
Build step 'Execute shell' marked build as failure
Finished: FAILURE`
ReInstalling Jenkins solved my problem !! It was due to corrupt plugin which happened due to server restart.
Thanks Everyone
I have not seen the exact command of svn you have used in test.sh, but would advice you to give full path of SVN in your calling line, eg /usr/bin/svn co .....
And if also possible make an entry in your test.sh for export PATH and export LD_LIBRARY_PATH setting them to values which are paths of the mentioned .so files
I see you're using Hudson/Jenkins. Hudson and Jenkins use SVNKit internally when checking stuff in and out of Subversion. This means that the command line svn client may not be installed on your system, or that it may have other problems.
It is also possible that there are multiple svn clients on your system. For example, you may have one under /usr/bin/svn and one under /usr/local/bin/svn. If Subversion is working from the command line, but not in the script, you may have a different $PATH setup when you're executing from the command line vs. the script from Hudson/Jenkins. You can add to your script (if it's BASH) the line type svn to see where your executing svn from. It may be different from what you are using from the command line. It may also be nice to print out $PATH as part of your script.
It would also be helpful to see the svn command that your script is executing, and tell us what you're trying to do. You can also add to your script the following lines:
PS4="\$LINE: "
set -xv
These lines will turn on shell script debugging, and help you locate where your script is having problems.
This will give you some clues as to what is going wrong in your script.
Reply
Thanks David. Here only 1 svn path exists (usr/bin/svn)but created as a softlink see -->cd /usr/bin/svn lrwxrwxrwx 1 root system 26 Jul 1 14:34 svn -> ../../opt/freeware/bin/svn. Also soflink of libs.so is created see --> lrwxrwxrwx 1 root system 15 Sep 13 18:15 libssl.so -> libssl.so.1.0.1 .......... Is it possible that softlink is creating these problems ?? Before requesting to remove these softlinks ,i need confirmation that these softlinks are creating problems.
Softlinking isn't unusual for Unix. For example, I have Ant, Grails, Maven, Subversion, and many other packages installed under /opt on my Mac. In order not to have to include each and every one of these in my path, I soft link all of the binaries for those programs under /usr/local/bin. About 80% of the programs under /usr/local/bin are merely soft links elsewhere.
Library soft links are also very common. This usually has to do with version numbering. When a program requests a library, it may or may not include the library's version number. So, you have libfoo-2.0.3.so on your drive. This is the actual version of foo. However, few programs will request that particular version. Instead, they may simply request they need Version #2 of foo or just say they need to link to foo.
To handle this, you will have libfoo2.0.3.so soft linked to libfoo-2.so for programs that specify they need version 2 of foo. Then, libfoo-2.so will be soft linked to libfoo.so. This way, libfoo will be called no matter what. If I install, libfoo2.0.4.so, I can change the link to libfoo-2.so to point to version 2.0.4 instead of version 2.0.3, and anything that depends upon Foo will be picking up the correct version.
Instead, let's look at the error message:
Could not load module /opt/freeware/lib/libssl.so.
   Dependent module /usr/lib/libcrypto.a(libcrypto.so.1.0.1) could not be loaded.
   Member libcrypto.so.1.0.1 is not found in archive
For some reason, it couldn't access the file /usr/lib/libcryto.a. Is this file on you machine? Is it in /usr/lib? If not, where is it located?
So, where did you get this version of Subversion from? Why is the link to the /opt/freeware/bin/ directory? Was this part of your system?
It could be that Subversion on your system is not complete and never did work. In Jenkins, the Subversion repository is accessed by the SVNKit Jarfile which is embedded inside Jenkins/Hudson itself, so it wouldn't really be a surprise to find that the Subversion binary didn't work.
Are you able to do anything with Subversion from the command line? If not, you may have to install a new version of Subversion from Perzl which is where CollabNet points to for an AIX version of Subversion. (It's at least up to date at version 1.8.4).
You may even want to change the soft link at /usr/bin/svn to point to the newer, working version of Subversion.

Resources