gradle / gradle

Adaptable, fast automation for all
https://gradle.org
Apache License 2.0
16.36k stars 4.59k forks source link

FileNotFoundException when using SSH to build from source dependencies #19924

Open ZakTaccardi opened 2 years ago

ZakTaccardi commented 2 years ago

I forked a library for an immediate fix for an issue and attempted to build that code from source, using the following:

sourceControl {
    gitRepository(java.net.URI.create("ssh://git@github.company.com/ZakTaccardi/forked-repo.git")) {
        producesModule(..) 
    }
}

This worked locally for me, but failed on our CI servers with the following exception:

Caused by: com.jcraft.jsch.JSchException: java.io.FileNotFoundException: /home/tools/.ssh/id_github_rsa (No such file or directory)
    at com.jcraft.jsch.KeyPair.load(KeyPair.java:543)
    at com.jcraft.jsch.IdentityFile.newInstance(IdentityFile.java:40)
    at com.jcraft.jsch.JSch.addIdentity(JSch.java:406)
    at com.jcraft.jsch.JSch.addIdentity(JSch.java:366)
    at org.eclipse.jgit.transport.JschConfigSessionFactory.getJSch(JschConfigSessionFactory.java:372)
    at org.eclipse.jgit.transport.JschConfigSessionFactory.createSession(JschConfigSessionFactory.java:308)
    at org.eclipse.jgit.transport.JschConfigSessionFactory.createSession(JschConfigSessionFactory.java:175)
    at org.eclipse.jgit.transport.JschConfigSessionFactory.getSession(JschConfigSessionFactory.java:105)
    ... 258 more
Caused by: java.io.FileNotFoundException: /home/tools/.ssh/id_github_rsa (No such file or directory)
    at com.jcraft.jsch.Util.fromFile(Util.java:508)
    at com.jcraft.jsch.KeyPair.load(KeyPair.java:540)
    ... 265 mor

After looking at how our CI has ssh setup, I noticed it was using an .ssh/config file, while I am not locally. My guess is that the CI server setup is doing something modern/fancy with .ssh/config and the outdated jsch lib that Gradle uses internally ends up thinking that /home/tools/.ssh/id_github_rsa - when it in fact, does not.

Updating the ssh lib to something more modern would likely solve this issue - something along the lines of https://github.com/gradle/gradle/issues/19028

Your Environment

Using Gradle 7.4

Issue occurred on both these VMs

Did not occur on my local MacOS 11.16.3

ljacomet commented 4 months ago

Hey @ZakTaccardi ,

8.7 nightlies have an updated JGit / SSH setup. Could you try and see if it solves the issue?