How to add a jar as a buildscript dependency in a portable way?

I have a build.gradle that “apply from:” a custom task

I need this custom task to be able to use the classes in a local jar file I also need this to be portable, such that I can push the jar to source control and not have to have every developer add it to their groovy classpath by hand

I don’t quite understand your explanations (e.g. the first sentence). Can you elaborate?

Yeah, sorry. I wrote that exceptionally poorly. Let me try again.

Note that this is an android project, but I beleive it to be a gradle specific question.

I have a build.gradle file (the autogenerated one created via a new project in android studio) I also have a custom task in another gradle file (called betterConnectedTest.gradle) The custom task is added to the build.gradle using apply from:‘betterConnectedTest.gradle’

I also have a jar that contains some convenience classes that I would like to consume in betterConnectedTest.gradle. This jar is checked into our source control and won’t be in any configured groovy classpath by default.

I need to find a portable way for betterConnectedTest.gradle to consume that jar

Depending on whether other people also have access to your source control (Do you really mean source control, not artifact repository?)

If they do not have access: Have you considered putting betterConnectedTest.gradle in a plugin, together with your jar? http://www.gradle.org/docs/current/userguide/custom_plugins.html Then your plugin build would produce another jar (which in turn would include the ‘consumed’ jar), that you could give to other people. At least it would only be one file then. They would then write in their scripts:

buildscript {
    dependencies {
        classpath files('better-connected-plugin-0.1.jar')
    }
}
    apply plugin: 'better-connected'

If they do have access: I think you should consider using an artifact repository anyways, where everyone has access and publish every jar there that you would like to use. And then their buildscript would be:

buildscript {
    repositories {
        maven {
// for example
            url 'http://your-company-repo/'
        }
    }
    dependencies {
        classpath 'your-company:better-connected-plugin:0.1'
    }
}
    apply plugin: 'better-connected'

Sounds like you just need a ‘buildscript’ block that adds the Jar to the build script class path. Since the Jar is under source control, you can rely on using a relative path. Due to a known limitation, the ‘buildscript’ block will have to be added to ‘build.gradle’ rather than ‘betterConnectedTest.gradle’ as shown in Thomas’ first snippet. You’ll just have to replace the Jar path with a path to the Jar that’s under source control, and use ‘apply from:‘betterConnectedTest.gradle’’ rather than ‘apply plugin: …’.