Skip to content

Instantly share code, notes, and snippets.

@glombard
Forked from kotucz/build-robolectric.gradle
Created October 7, 2015 02:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glombard/cf17025b78b8866ad26c to your computer and use it in GitHub Desktop.
Save glombard/cf17025b78b8866ad26c 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
}
}
}
@bizillcizole
Copy link

Thanks for this!

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