java - Ant sshexec task called from gradle doesn't show output -
i want use apache ant sshexec task in gradle custom task. problem task doesn't work (output not shown in console , sshexec action not executed). how use it:
configurations { sshexecanttask } repositories { mavencentral() } dependencies { sshexecanttask 'org.apache.ant:ant-jsch:1.7.0' } // ---------------------------------------------------- import java.nio.file.filealreadyexistsexception; import java.nio.file.files class mycustomtask extends defaulttask { @taskaction def build() { string command = "" command = 'cmd.exe /c mdir c:\\aadd' runsshcommand(command) } private void runsshcommand(string command) { string host = "host" string username = "username" string password = "password" ant.taskdef(name: 'sshexec', classname: 'org.apache.tools.ant.taskdefs.optional.ssh.sshexec', classpath: project.configurations.sshexecanttask.aspath) // command not executed; why? ant.sshexec(host: host, username: username, password: password, command: command, trust: 'true', failonerror: 'true') } } [edit] i've tested sshexec , results:
- the command
cmd.exe /c echo test > c:\testresult.txtstarted ant works correctly , output returned file. - the command
cmd.exe /c echo test > c:\testresult.txtstarted gradle works correctly , output returned file. great! - the command
cmd.exe /c echo teststarted ant works correctly , output returned stdout. ! - the command
cmd.exe /c echo teststarted gradle works correctly output not returned stdout. ! - the command
cmd.exe /c mkdir c:\\\\inetpub\\\\ftproot\\\\temp\\\\jakisnowykatalogstarted ant works correctly , directory created (i need use\\\\path separator because\\,\,/doesn't work) - the command
cmd.exe /c mkdir c:\\\\inetpub\\\\ftproot\\\\temp\\\\jakisnowykatalogstarted gradle doesn't work , directory not created.
i should add want connect windows ssh server (not unix/mac) i've tested commands mac shh without success. please help!
[another edit] i've created groovy test code uses jsch library execute command , works. still don't know why ant task doesn't work.
import com.jcraft.jsch.* import java.util.properties; private void jschtest() { session session = null channel channel = null try { jsch jsch = new jsch() session = jsch.getsession("host", "login", 22) session.setpassword("password") properties config = new properties() config.put("stricthostkeychecking", "no") session.setconfig(config) session.connect() string command = "cmd.exe /c mkdir c:\\gradledir" channel = session.openchannel("exec"); ((channelexec)channel).setcommand(command); channel.connect() } catch (exception e) { println e.getmessage() } { if (session!=null) { session.disconnect() } if (channel!=null) { channel.disconnect() } } }
assuming declare task of type mycustomtask , execute correctly, see no reason why ant task wouldn't executed. problem more elsewhere (e.g. wrong configuration of ant task).
Comments
Post a Comment