However, with Gradle 1.12 this produces the following warning: “Trying to override old definition of datatype scp”
This makes me think that the SCP task is just ready to use in Gradle. In fact, if I completely skip the configuration above and just try to invoke:
task myTask {
doLast {
ant.scp(…)
}
}
I receive the following error: “Problem: failed to create task or type scp \ Cause: the class org.apache.tools.ant.taskdefs.optional.ssh.Scp was not found.”.
So, the SCP task is known, however I need to add ‘org.apache.tools.ant.taskdefs.optional.ssh.Scp’ to the Ant classpath. Unfortunately, just adding this dependency to the buildscript (“classpath” configuration) does not work (this is a bit surprising for me). So, can I add something to the global Ant classpath, instead of to just a specific Ant taskdef classpath?
Or else, is there a way to get rid of that “Trying to override old definition of datatype scp” warning?
I think that using the taskdef should work (I actually never run the task), but that warning makes me think there’s a better way to handle this. This better and more elegant way seems to be just a way to add a JAR to Ant’s classpath from Gradle, but I searched the Javadocs and user guide and I was not able to find a solution. Also, adding these JARs to Gradle buildscript own classpath seemed to be the obvious solution but it does not work.
So, are you saying that the already defined tasks that need optional JARs must be overridden in any case to make them work, because there’s no way to fill in Ant’s own classpath?
Redefining the scp task doesn’t strike me as the right approach, as that task ships with core Ant, not with ant-jsch. Anyway, it would be good to know if this solves the problem (I don’t think it will).
In general, Gradle tries to isolate projects from each other (so that they don’t interfere), and I’m not aware of a good way to add classes in such a way that core Ant classes can see them. But perhaps somebody else has figured this out already and can weigh in.
If I go with the taskdef way, it actually works, although I have to adjust some secondary aspects to make this work decently in a multiproject environment (where I want to use the Ant SCP task on a number of subprojects).
Anyway I agree with you that I shouldn’t need to redefine the Scp task if it’s built in, I should just need to add the necessary dependencies to Ant’s own classpath
Anyone else at Gradle that can give me some hints?
Also, an acceptable solution for my specific problem would even be to get rid of Ant completely and find a way to do an SCP operation with Gradle itself. However I couldn’t find solutions on the Internet apart from using Ant. And I would prefer to avoid to use the jsch library directly…