Skip to content

Instantly share code, notes, and snippets.

@kotucz
Last active November 5, 2019 12:13
Show Gist options
  • Save kotucz/60ae91767dc71ab7b444 to your computer and use it in GitHub Desktop.
Save kotucz/60ae91767dc71ab7b444 to your computer and use it in GitHub Desktop.
Robolectric runtime dependencies downloader
/**
* Module that includes this will be configured to use offline dependencies for Robolectric
* This downloads robolectric dependencies once into the root project
*/
def robolectricDependenciesFolder = rootProject.buildDir.path + "/robolectric-dependencies"
// configuration that resolves Robolectric runtime dependencies
configurations.create('robolectricRuntime')
// explicitly name required runtime dependencies
dependencies {
// runtime dependencies for org.robolectric:robolectric:3.0
robolectricRuntime "org.ccil.cowan.tagsoup:tagsoup:1.2"
robolectricRuntime "org.robolectric:android-all:4.1.2_r1-robolectric-0"
robolectricRuntime "org.robolectric:shadows-core:3.0:16"
robolectricRuntime "org.json:json:20080701"
}
rootProject.task(type: Copy, overwrite: true, "downloadRobolectricDependencies") {
println "downloadRobolectricDependencies " + robolectricDependenciesFolder
from configurations.robolectricRuntime
into robolectricDependenciesFolder
}
tasks.all {
if (it.name.startsWith("test")) {
it.dependsOn(rootProject.tasks.findByName("downloadRobolectricDependencies"))
}
}
// tests have own system properties, cannot be set from gradle via -D
android {
testOptions {
unitTests.all {
systemProperty 'robolectric.offline', 'true'
systemProperty 'robolectric.dependency.dir', robolectricDependenciesFolder
}
}
}
@TigerSkinZhang
Copy link

it doesn't work...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment