Is there a way to set Ant global classpath?


(mauromol) #1

I need to use the SCP Ant task defined by ‘org.apache.ant:ant-jsch:1.7.1’. First try is to do as the user guide suggests:

configurations { scpAntTask }

dependencies { scpAntTask ‘org.apache.ant:ant-jsch:1.7.1’ }

ant.taskdef(name: ‘scp’, classname: ‘org.apache.tools.ant.taskdefs.optional.ssh.Scp’, classpath: configurations.scpAntTask.asPath)

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?


(Peter Niederwieser) #2

So everything is working as expected, but you would like to get rid of the warning?


(mauromol) #3

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?


(Peter Niederwieser) #4

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.


(mauromol) #5

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 :frowning:

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…


(Peter Niederwieser) #6

I’ve successfully used http://gradle-ssh-plugin.github.io/, which also provides ‘put’ and ‘get’ operations for file transfers.


(mauromol) #7

Interesting, thank you. I have a problem to make the put work, however, I already opened an issue for that plugin.

Anyway, if someone else here can shred some light on the Ant classpath issue it would be very helpful and useful (even for the future).