Unable to add configurations in buildscript section

I’m trying to use the sshexec optional task with Gradle which fails with a

No such property: sshexec for class: org.gradle.api.internal.project.DefaultAntBuilder

I’ve read on several places on the internet that a solution would be to create a new configuration (for example called antClasspath), declare the ant-jsch package as a dependency in this configuration and then somehow (different ideas in different posts) modify the ant classpath to include the new package. However, I’m not even able to add it as a dependency to the new configuration. I’m using the following code:

buildscript {
  configurations {
    antClasspath
  }
    dependencies {
    println("All configs: " + configurations.toList())
    println("All configs for project: " + project.configurations.toList())
          antClasspath 'org.apache.ant:ant-jsch:1.8.2'
  }

When I run a task, I get the following output:

All configs: [configuration ':classpath']
All configs for project: [configuration ':antClasspath']
  FAILURE: Build failed with an exception.
  * Where:
Build file 'build.gradle' line: 247
  * What went wrong:
A problem occurred evaluating root project 'test'.
> No signature of method: org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.antClasspath() is applicable for argument types: (java.lang.String) values: [org.apache.ant:ant-jsch:1.8.2]

So it seems like the configuration I add in the buildscripts closure is added to the project instead of whatever I’m configuring in the buildscript closure.

I might be missing something obvious here, but all documentation I read makes me think that I should be able to do what I’m doing…

No (longer) sure what the problem is. Do you have a ‘repositories’ block in the ‘buildscript’ section?

Thanks for the quick reply, but unfortunatly that’s just a copy-paste error. I have a repositories block. The whole buildscript block looks like

buildscript {
  configurations {
    antClasspath
  }
  dependencies {
    println("All configs: " + configurations.toList())
    println("All configs for project: " + project.configurations.toList())
    antClasspath 'org.apache.ant:ant-jsch:1.8.2'
  }
  repositories {
    mavenCentral()
  }
}

Wait a minute. It’s uncommon (and probably not supported) to declare a configuration in the ‘buildscript’ section. Usually one just adds dependencies to the predefined ‘classpath’ configuration there, in order to get dependencies onto the build script class path. The ‘antClasspath’ configuration should be declared and populated outside the ‘buildscript’ section. Of course you’ll still have to use it somewhere.

Ah. I thought I tried that and didn’t get access to it from the build script. Must have been some other error I made, now the dependency definitions is working. Thanks!