alexvasilkov / GradleGitDependenciesPlugin

Gradle plugin to add external git repos as project dependencies
Apache License 2.0
105 stars 15 forks source link

Git dependency "remote hung up unexpectedly" Missing dependency on org.eclipse.jgit.ssh.jsch? #20

Closed StrangeNoises closed 3 years ago

StrangeNoises commented 3 years ago

I get this on my first attempt to get this plugin going, against an in-house git server accessed via ssh.

"remote hung up unexpectedly"

With stacktrace:

Caused by: org.eclipse.jgit.errors.TransportException: git@git.merus.co.uk:Toolbox.git: remote hung up unexpectedly
        at org.eclipse.jgit.transport.TransportGitSsh$SshFetchConnection.<init>(TransportGitSsh.java:270)
        at org.eclipse.jgit.transport.TransportGitSsh.openFetch(TransportGitSsh.java:144)
        at org.eclipse.jgit.transport.FetchProcess.executeImp(FetchProcess.java:105)
        at org.eclipse.jgit.transport.FetchProcess.execute(FetchProcess.java:91)
        at org.eclipse.jgit.transport.Transport.fetch(Transport.java:1260)
        at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:211)
        ... 157 more
Caused by: java.lang.NullPointerException: Cannot invoke "org.eclipse.jgit.transport.SshSessionFactory.getSession(org.eclipse.jgit.transport.URIish, org.eclipse.jgit.transport.CredentialsProvider, org.eclipse.jgit.util.FS, int)" because "this.sch" is null
        at org.eclipse.jgit.transport.SshTransport.getSession(SshTransport.java:107)
        at org.eclipse.jgit.transport.TransportGitSsh$SshFetchConnection.<init>(TransportGitSsh.java:254)
        ... 162 more

The SshTransportFactory isn't getting initialised. I think this is because the jgit ssh implementation library is not in the classpath, because it's not declared in the dependencies. I think it probably needs

implementation group: 'org.eclipse.jgit', name: 'org.eclipse.jgit.ssh.jsch', version: '(version)'

in your build.gradle. I'm afraid my gradle-fu doesn't seem to be up to forcibly injecting it, and its transitive dependencies on jsch etc., into the classpath for gradle at the initialization stage (when settings.gradle is read) or I'd have tested that as a workaround...

alexvasilkov commented 3 years ago

Thanks for reporting!

Indeed, the issue was caused by the recent migration from grgit to jgit (because grgit is hosted with recently shut down jcenter).

First of all, it turns out Jgit moved SSH support into separate libs as of version 5.8, so it have to be explicitly included, exactly as you pointed out. But just including the correct lib didn't work as Jgit still cannot find the correct SshSessionFactory (seems like Java ServiceLoader does not work well with Gradle plugins). Luckily it can be set manually.

But it turned out that org.eclipse.jgit.ssh.jsch does not work well, somehow I got vague "Auth fail" errors even though the old version based on grgit worked just fine. I ended up copying grgit hack that manually checks for ssh in PATH and sets GIT_SSH variable for Jgit to use system command instead of own broken implementation.

Long story short - it should be fixed in v2.0.4 now.