How can ant optional tasks be used within a POGO defined within the 'buildSrc' directory?

Hello all,

I have a multiproject build process which I am refactoring to use POGOs.

I am attempting to refactor some code which executes commands on a remote SLES server into one of these POGOs. Currently that code uses ant’s ‘SSHExec’ optional task (it has been configured in much the same way as is described here:

The POGO looks like this:

public class RemoteSLESCommand {
    static def executeRemoteCommand ( final String pHost , final String pUsername , final String pPassword , final boolean pTrust , final boolean pFailOnError , final String pCommand ) {
        println "executeRemoteCommand : pHost = $pHost ; pUsername = $pUsername ; pTrust = $pTrust ; pFailOnError = $pFailOnError ; pCommand = $pCommand "
        ( new AntBuilder() ).sshexec ( host
     : pHost
                                     , username
 : pUsername
                                     , password
 : pPassword
                                     , trust
    : pTrust
                                     , failonerror: pFailOnError
                                     , command
  : pCommand
      static def createFolder ( final String pHost , final String pUsername , final String pPassword , final String pPathToRemoteFolder ) {
        println "Creating remote folder: $pUsername@$pHost:$pPathToRemoteFolder"
        executeRemoteCommand ( pHost , pUsername , pPassword , true , true , " mkdir -p $pPathToRemoteFolder " )

and it sits in the ‘buildSrc’ directory, like this:


The POGO compiles without any problems, but when I create a task (in let’s say the build.gradle file which sits in the root directory) which attempts to invoke one of the methods provided by it, e.g.:

task x {
    doLast {
        RemoteSLESCommand.createFolder ( '<host>' , '<username>' , '<password>' , '$HOME/test' )

then I receive the following error at runtime:

* What went wrong:
Execution failed for task ':x'.
> Problem: failed to create task or type sshexec
  Cause: the class was not found.
          This looks like one of Ant's optional components.
  Action: Check that the appropriate optional JAR exists in
        -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

That’s fine - but I don’t know how to make gradle see the missing JARs!

Can anyone provide an example of how to configure gradle such that it will find the JARs neccessary at runtime?



You’re missing crucial bits of the config.

Have a look at the example again, particular the use of taskdef.