Created
April 24, 2014 20:52
-
-
Save eightbitraptor/11269109 to your computer and use it in GitHub Desktop.
Build.gradle for Rubolectric integration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
buildscript { | |
repositories { | |
mavenCentral() | |
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' } | |
} | |
dependencies { | |
classpath 'com.android.tools.build:gradle:0.9.+' | |
classpath 'com.novoda.gradle:robolectric-plugin:0.0.1-SNAPSHOT' | |
} | |
} | |
allprojects { | |
repositories { | |
mavenCentral() | |
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' } | |
} | |
} | |
apply plugin: 'android' | |
apply plugin: 'robolectric' | |
sourceSets { | |
androidTest { | |
java.srcDir file('src/test/java') | |
} | |
} | |
android { | |
compileSdkVersion 19 | |
buildToolsVersion "19.0.3" | |
defaultConfig { | |
minSdkVersion 15 | |
targetSdkVersion 19 | |
versionCode 1 | |
versionName "1.0" | |
} | |
buildTypes { | |
release { | |
runProguard false | |
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' | |
} | |
} | |
sourceSets { | |
instrumentTest.setRoot('src/test') | |
testLocal { | |
java.srcDir file('src/test/java') | |
} | |
} | |
} | |
dependencies { | |
compile 'com.android.support:appcompat-v7:19.+' | |
compile fileTree(dir: 'libs', include: ['*.jar', '*.aar']) | |
androidTestCompile 'org.robolectric:robolectric:2.+' | |
androidTestCompile 'junit:junit:4.+' | |
} | |
task addTest { | |
def src = ['src/test/java'] | |
def file = file("app.iml") | |
doLast { | |
} | |
def parsedXml = (new XmlParser()).parse(file) | |
def node = parsedXml.component[1].content[0] | |
src.each { | |
def path = 'file://$MODULE_DIR$/' + "${it}" | |
def set = node.find { it.@url == path } | |
if (set == null) { | |
new Node(node, 'sourceFolder', ['url': 'file://$MODULE_DIR$/' + "${it}", 'isTestSource': "true"]) | |
def writer = new StringWriter() | |
new XmlNodePrinter(new PrintWriter(writer)).print(parsedXml) | |
file.text = writer.toString() | |
} | |
} | |
} | |
// always do the addtest on prebuild | |
gradle.projectsEvaluated { | |
preBuild.dependsOn(addTest) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Shouldn't this say "Robolectric" in the title?