Regression in build script compilation on 2.12

(Danny Thomas) #1

The follow build script (used to configure SSH agent support for Git clones with gradle-git) fails to compile on Gradle 2.12, but successfully compiled in previous releases:

buildscript {
    repositories {
    dependencies {
        classpath 'org.ajoberstar:gradle-git:0.5.0'
        classpath 'com.jcraft:jsch.agentproxy.jsch:0.0.5'
        classpath 'com.jcraft:jsch.agentproxy.usocket-jna:0.0.5'
        classpath 'com.jcraft:jsch.agentproxy.sshagent:0.0.5'

import com.jcraft.jsch.IdentityRepository
import com.jcraft.jsch.JSch
import com.jcraft.jsch.JSchException
import com.jcraft.jsch.Session
import com.jcraft.jsch.agentproxy.AgentProxyException
import com.jcraft.jsch.agentproxy.Connector
import com.jcraft.jsch.agentproxy.RemoteIdentityRepository
import com.jcraft.jsch.agentproxy.USocketFactory
import com.jcraft.jsch.agentproxy.connector.SSHAgentConnector
import com.jcraft.jsch.agentproxy.usocket.JNAUSocketFactory
import org.ajoberstar.gradle.git.tasks.*
import org.eclipse.jgit.transport.JschConfigSessionFactory
import org.eclipse.jgit.transport.OpenSshConfig
import org.eclipse.jgit.transport.SshSessionFactory
import org.eclipse.jgit.util.FS

SshSessionFactory.setInstance(new IdBasedFactory())

 * Uses default keys and possible ssh-agent for keys in Jsch session.
class IdBasedFactory extends JschConfigSessionFactory {
    protected void configure(OpenSshConfig.Host host, Session session) {
        session.setConfig("StrictHostKeyChecking", "false");

    protected JSch createDefaultJSch(FS fs) throws JSchException {
        Connector con = null;
        try {
                //USocketFactory usf = new JUnixDomainSocketFactory();
                USocketFactory usf = new JNAUSocketFactory();
                con = new SSHAgentConnector(usf);
        } catch(AgentProxyException e){
  "Unable to find SSH Agent")

        if (con == null) {
            JSch jsch = super.createDefaultJSch(fs)
            try {
                File sshDir = new File("${System.getenv()['HOME']}/.ssh")
                // Bob T Builder uses id_rsa by default
                File idFile = new File(sshDir, 'id_rsa')
                if (!idFile.exists()) {
                    idFile = new File(sshDir, 'id_dsa')

            } catch (JSchException e) {
                logger.warn("Unable to set identify", e)
            return jsch
        } else {
            final JSch jsch = new JSch();
            jsch.setConfig("PreferredAuthentications", "publickey");
            IdentityRepository irepo = new RemoteIdentityRepository(con);
            knownHosts(jsch, fs)
            return jsch

Updating the import to import to import org.eclipse.jgit.transport.OpenSshConfig.Host and changing the reference to Host resolves the issue.