Android – add dependencies in eclipse using gradle
•
Android
I am using the gradle ide plug-in of eclipse. I created a custom task in the 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 referenced are not added in eclipse. I import org. JUnit. Test;, import org.robolectric.Robolectric; Wait, it can't be solved. I tried to click item – > gradle – > refresh dependencies, but it didn't help
resolvent:
I found the solution myself. Add it to the build.gradle file:
apply plugin: 'eclipse'
eclipse {
classpath {
plusConfigurations += configurations.unitTestCompile
}
}
Then right-click the item – > gradle – > refresh dependencies
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码