我正在使用Eclipse的Gradle IDE插件,我在build.gradle文件中创建了一个自定义任务:
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
问题是我引用的依赖项没有在Eclipse中添加,我得到导入org.junit.Test;,import org.robolectric.Robolectric;等等,无法解决.我试过点击项目 – > Gradle – >刷新依赖关系但无济于事.
解决方法:
自己找到了解决方案.将其添加到build.gradle文件中:
apply plugin: 'eclipse'
eclipse {
classpath {
plusConfigurations += configurations.unitTestCompile
}
}
然后右键单击项目 – > Gradle – >刷新依赖关系.
标签:android,eclipse,gradle
来源: https://codeday.me/bug/20190629/1323300.html