Steps for building robolectric and the gradle plugin locally
Robolectric is a pure maven build. You'll need maven.
$ brew install maven
Robolectric currently works with sdk 18. Make sure you have
downloaded sdk 18 (with google apis) using the android
tool.
You'll need the support library version 19.0.1 too.
$ android update sdk -u --all --filter addon-google_apis-google-18,extra-anroid-support
Then, follow the steps in the robolectric readme to install the needed dependencies into your local maven repository.
For robolectric to build, I needed to export JAVA_HOME
pointing
to the result of the OSX java_home
command.
$ export JAVA_HOME=$(/usr/libexec/java_home)
Grab a copy of the Robolectric source. After you have the source, you'll probably want to checkout the latest release tag and then branch so you've got a clean workspace.
To distinguish your copy from the real Robolectric, edit the groupId
in the top level pom.xml
.
<groupId>com.example</groupId>
You'll then need to edit the pom.xml
files in all the
module projects to point at your altered groupId.
<parent>
<groupId>com.example</groupId>
<artifactId>robolectric-parent</artifactId>
...
</parent>
Leave the version unchanged for now. The module projects have some
dependencies on others. Edit the groupId
in the dependencies
section of the pom.xml
file too. But instead of hard-coding the
groupId, we can just use the dynamic maven property. For example:
<dependencies>
<dependency>
<groupId>${parent.groupId}</groupId>
<artifactId>robolectric-annotations</artifactId>
</dependency>
...
You'll need to edit dependencies in all the modules.
Once the groupId is in shape, building is simple:
$ mvn package
Maven makes it super easy to publish locally:
$ mvn install
(You can simply run mvn install
as it depends on the package
target.)
This deposites the artifacts from the last step into your local
maven repository (usually ~/.m2/repository
).
If you need to update your version, use something like:
$ mvn versions:set -DnewVersion=Your.Desired.Version[-SNAPSHOT]
(-SNAPSHOT
is optional.)
For now, make sure ANDROID_HOME
is defined in your environment:
$ export ANDROID_HOME="/path/to/your/sdk"
Note: You cannot use local.properties
for this build because
the Android plugin is a compile time dependency of the plugin
project. There may be a way to fix this but I haven't looked into
it yet.
Grab the robolectric-gradle-plugin.
You may want to change the groupId so that your version doesn't
shadow the released plugin on maven central. Edit the
build.gradle
script:
group = 'com.example'
Thanks gradle!
$ ./gradlew build
$ ./gradlew install
This generates a pom file and deposits the artifacts into ~/.m2/repository
.
Point your build script at your local maven:
repositories {
mavenLocal()
// First wins. Others repos. Order matters.
}
Don't forget to add mavenLocal()
to the buildscript repositories
for your local installation of the android plugin.
Take a look at my example project.