Reputation: 1331
I'm using the Gradle IDE plugin for Eclipse and I've created a custom task in my build.gradle file:
sourceSets {
unitTest {
java.srcDirs = ['tests']
}
}
dependencies {
unitTestCompile files("$project.buildDir/classes/debug")
unitTestCompile 'junit:junit:4.11'
unitTestCompile 'org.robolectric:robolectric:2.1.1'
unitTestCompile 'com.google.android:android:4.0.1.2'
}
configurations {
unitTestCompile.extendsFrom runtime
unitTestRuntime.extendsFrom unitTestCompile
}
task unitTest(type:Test, dependsOn: assemble) {
description = "run unit tests"
testClassesDir = project.sourceSets.unitTest.output.classesDir
classpath = project.sourceSets.unitTest.runtimeClasspath
}
build.dependsOn unitTest
The problem is that the dependencies I've referenced are not added in Eclipse and I get the error that import org.junit.Test;
, import org.robolectric.Robolectric;
and so on, can't be resolved. I've tried right clicking on the project -> Gradle -> Refresh Dependencies but to no avail.
Upvotes: 4
Views: 615
Reputation: 1331
Found the solution myself. Add this to the build.gradle file:
apply plugin: 'eclipse'
eclipse {
classpath {
plusConfigurations += configurations.unitTestCompile
}
}
and then right-click on project -> Gradle -> Refresh Dependencies.
Upvotes: 3