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 {
jcenter()
}
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 {
@Override
protected void configure(OpenSshConfig.Host host, Session session) {
session.setConfig("StrictHostKeyChecking", "false");
}
@Override
protected JSch createDefaultJSch(FS fs) throws JSchException {
Connector con = null;
try {
if(SSHAgentConnector.isConnectorAvailable()){
//USocketFactory usf = new JUnixDomainSocketFactory();
USocketFactory usf = new JNAUSocketFactory();
con = new SSHAgentConnector(usf);
}
} catch(AgentProxyException e){
logger.info("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')
}
jsch.addIdentity(idFile.getAbsolutePath())
jsch.setKnownHosts("${sshDir.getAbsolutePath()}/known_hosts")
} 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);
jsch.setIdentityRepository(irepo);
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.