Add a directory of .class files to the buildscript classpath

(Justin Ryan) #1

Is there a way to add a directory of .class files to the buildscript classpath? I’m trying to rapidly develop a plugin from Intellij, and currently the IDE is building a good classpath based on my dependencies and where it put the .class files (i.e. out/production/${moduleName}). While it can find my resources (e.g. the plugin descriptor in META-INF) it can not find the .class file for my plugin. IIRC some classloader filters classes available to the script, specifically to only org.gradle package. (This is really annoying, because I can’t just drop a plugin in the gradle lib directory or add something to the system classpath, which drastically simplifies distributing a plugin in an enterprise across hundreds of projects. I’d say its equivalent to giving the core developers a back-door when they write plugins.)

My alternative was to add my directory of .class files as a buildscript dependency, like we can do with .jar files. e.g.

rootProject { allprojects {
buildscript {
    dependencies {
        classpath files('/Users/jryan/Projects/gradle/out/production/nebula')

I would do this via an init script and only via the IDE. But it doesn’t work. Nor do a few variants, like new File(). Any ideas?

A recurring subject on the forums are about making plugins easier to develop. And being able to debug a plugin for another project directly from the IDE is really important to accomplish that.

(Peter Niederwieser) #2

Is there a way to add a directory of .class files to the buildscript classpath?

Adding them to ‘buildscript.dependencies.classpath’ should work.

(Justin Ryan) #3

Sorry for sounding like a n00b but can you be more specific?

I’ve tried a few variations on buildscript.dependencies.classpath and they are failing with messages like:

‘’’ > No such property: classpath for class: org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler ‘’’

If I use the DefaultDependencyHandler.add methods, it get errors like:

‘’’ > Cannot convert the provided notation to an object of type Dependency: /Users/jryan/Projects/gradle/out/production/nebula.

The following types/formats are supported:

  • Instances of Dependency.

  • Strings/CharSequences, e.g. ‘org.gradle:gradle-core:1.0’.

  • Maps, e.g. [group: ‘org.gradle’, name: ‘gradle-core’, version: ‘1.0’].

  • FileCollections, e.g. files(‘some.jar’, ‘someOther.jar’).

  • Projects, e.g. project(’:some:project:path’).

  • ClassPathNotation, e.g. gradleApi().

Comprehensive documentation on dependency notations is available in DSL reference for DependencyHandler type. ‘’’

Is there any way to print out what classpath it’s using to lookup the plugins? --debug doesn’t show it (though it seems to show just about everything else.)

In the best case it should look like this:

‘’’ buildscript {

dependencies {

classpath files([’/Users/jryan/Projects/gradle/out/production/nebula’])

} } ‘’’

That doesn’t fail on evaluation but it’ll fail looking up the plugin (though it does find the resoure).I’m confident that the class file in the that directory in the proper sub-directories.

(Peter Niederwieser) #4

In the best case it should look like this:

This is exactly how I’d expect it to work. I’ll have to try whether I can reproduce your problem. Note that there is a known issue that inside build scripts applied with ‘apply from:’, ‘apply plugin:’ must be followed by the fully qualified name of the plugin class (String identifier doesn’t work).

(Justin Ryan) #5

Just to finish up the topic, I too know this works I use it to run integration tests for my plugins straight in a slightly different way. This example looked identical. I’ve since given up on it, I must have had something else going on causing it to not work.