def robolectricDependenciesFolder = rootProject.buildDir.path + "/robolectric-dependencies"

configurations.create('robolectricRuntime')

dependencies {
    robolectricRuntime "org.ccil.cowan.tagsoup:tagsoup:1.2"
    robolectricRuntime "org.robolectric:android-all:6.0.0_r1-robolectric-0"
    robolectricRuntime "org.robolectric:shadows-core-v23:3.1.4"
    robolectricRuntime "org.json:json:20080701"
}

rootProject.task(type: Copy, overwrite: true, "downloadRobolectricDependencies") {
    println "downloadRobolectricDependencies " + robolectricDependenciesFolder
    from configurations.robolectricRuntime
    into robolectricDependenciesFolder
}

project.afterEvaluate {
  tasks.all {
      if (it.name.startsWith("test")) {
          it.dependsOn(rootProject.tasks.findByName("downloadRobolectricDependencies"))
      }
  }
}

android {
    testOptions {
        unitTests.all {
            systemProperty 'robolectric.offline', 'true'
            systemProperty 'robolectric.dependency.dir', robolectricDependenciesFolder
        }
    }
}

