对于我的Android项目,我想为我的集成测试运行测试HTTP服务器。我已经创建了一个配置并编写了一个任务来运行我的Groovy脚本来设置HTTP服务器
configurations {
stubs {
description = "Classpath for HTTP server for stubbed data"
visible = false
}
}
dependencies {
compile "com.android.support:support-v13:+"
stubs "org.codehaus.groovy:groovy:2.3.4"
stubs "com.github.tomakehurst:wiremock:1.46"
}
当我编辑Groovy脚本时,IntelliJ告诉我Groovy SDK尚未配置。
如何让IntelliJ使用属于stubs
配置的Groovy SDK?我无法使用Gradle提取的库创建Groovy SDK配置,因为IntelliJ告诉我Groovy发行版已被破坏,因为版本号无法确定。
我是否必须手动下载发行版?
答案 0 :(得分:0)
解决方案是将HTTP服务器的项目分离到一个单独的项目中,并使用Gradle's multiproject's ability设置Android测试以依赖于正在启动的HTTP服务器。因为单独的项目是一个Groovy项目,所以IntelliJ从项目的依赖项中读取要使用的Groovy版本,一切都很好。
dependencies {
compile "com.android.support:support-v13:+"
stubs project(":integration-server")
}
/*
* The android plugin defers creation of tasks in such a way that they can't be accessed eagerly as usual
* @see http://stackoverflow.com/questions/16853130/run-task-before-compilation-using-android-gradle-plugin
*/
gradle.projectsEvaluated {
connectedAndroidTest.dependsOn(":integration-server:startBackgroundServer")
// Note: finalizedBy is still @Incubating
connectedAndroidTest.finalizedBy(":integration-server:stopBackgroundServer")
}
集成服务器/的build.gradle
apply plugin: "groovy"
apply plugin: "spawn"
dependencies {
compile "org.codehaus.groovy:groovy:2.3.4"
compile "org.codehaus.groovy:groovy-ant:2.3.4"
compile "com.github.tomakehurst:wiremock:1.46"
}
task startBackgroundServer(type: SpawnProcessTask, dependsOn: "build") {
def cp = sourceSets.main.runtimeClasspath.asPath
command "java -cp $cp server"
ready "Started DelayableSocketConnector@0.0.0.0:8089"
}
task stopBackgroundServer(type: KillProcessTask)
为防止Gradle构建阻止,我使用Gradle Spawn Plugin在后台启动HTTP服务器。