Hi,
If I do this
task ls << {
ant.sshexec(host: 'myhost', username: 'myuser', trust: 'true', keyfile: "\${user.home}/.ssh/my-key.pem", command: 'ls /')
}
then gradle complains about the ant-jsch jar not being on the classpath:
Execution failed for task ':ls'.
> Problem: failed to create task or type sshexec
Cause: the class org.apache.tools.ant.taskdefs.optional.ssh.SSHExec was not found.
This looks like one of Ant's optional components.
Action: Check that the appropriate optional JAR exists in
-ANT_HOME/lib
-the IDE Ant configuration dialogs
Do not panic, this is a common problem.
The commonest cause is a missing JAR.
This is not a bug; it is a configuration problem
If I explicitely add a configuration for the jar and use taskdef like this:
configurations {
sshAntTask
}
repositories {
mavenCentral()
}
dependencies {
sshAntTask 'org.apache.ant:ant-jsch:1.8.4'
}
task ls << {
ant.taskdef(name: 'sshexec',
classname: 'org.apache.tools.ant.taskdefs.optional.ssh.SSHExec',
classpath: configurations.sshAntTask.asPath)
ant.sshexec(host: 'myhost', username: 'myuser', trust: 'true', keyfile: "\${user.home}/.ssh/my-key.pem", command: 'ls /')
}
Then the ls command works but I get the following warning just before that:
Trying to override old definition of datatype sshexec
I don’t mind the warning if its a known issue but I’d like make sure I’m not doing something wrong. This is just a little test case I resorted to try and clear things up because I was having problems using ant similarly from a custom task’s method.