Support for Creating a Local Repo for Testing

When writing a plugin there are some kind of integration tests which may need to download from repositories as part of the test. ONe way today to accomplish this is to use a flat repository i.e.


configuration {
   ext {
flatRepo = new File(buildDir,'tmp/integrationTest/flatRepo')
dependendencies {
  unittestRepo 'foo:bar:1.2.3'
   task setupTestRepo (type:Copy) {
  from ({configurations.unittestRepo.files})
  into flatRepo
   test {
  dependsOn setupTestRepo
  systemProperties FLATREPO : flatRepo.absolutePath


class SomeSpec extends Specification {
   static final File FLATREPO = new File( System.getProperty('FLATREPO') ?: 'build/tmp/integrationTest/flatRepo')
  Project project
  void setup() {
    project = ProjectBuilder.builder().build()
    project.with {
   logging.level = LIFECYCLE
      repositories {
     flatDir dirs : FLATREPO.absolutePath
    def 'something' () {
    project.dependencies {
      foo 'foo:bar:1.2.3'
     // ... now write the tests

This allows the dependencies to get downloaded once and tests can then be run offline afterwards.

The problem with this approach is that the author of hte tests have to managea all transitive dependencies themselves in the test code.

I suggest that an API is exposed to the build script can mirror a set of dependencies (including transitives) into a locally specified ivy/maven repo, as specified by the build script. I don’t want this to go to the user’s local M2 as this might cause pollution of a working repo. For testing we would want to isolate the repo and keep it local to the build. I know the Ivy/Ant already supports this somehow, but that part of the API is not actually exposed into Gradle.

Probably something like this

task localRepo( type : CopyDependencies ) {
  configuration myTestRepo
  into file('build/tmp/foo/bar')