2

For my Android project I want to run a test HTTP server for my integration tests. I've created a Configuration and have written a task to run my Groovy script the sets up the HTTP server

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"
}

When I edit the Groovy script IntelliJ tells me that the Groovy SDK hasn't been configured.

How can I have IntelliJ use the Groovy SDK that is part of the stubs Configuration? I can't create a Groovy SDK configuration using the Gradle fetched libraries as IntelliJ tells me that the Groovy distribution is broken because the version number can't be determined.

Am I forced to have to download the distribution manually?

kierans
  • 2,034
  • 1
  • 16
  • 43

1 Answers1

0

The solution was to separate out the project for the HTTP server into a separate project and use Gradle's multiproject's ability to set up the Android tests to depend on the HTTP server being started. Because the separate project is a Groovy project, IntelliJ reads the Groovy version to use from the project's dependencies and all is well.

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")
}

integration-server/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)

To prevent the Gradle build blocking I'm using a Gradle Spawn Plugin to launch the HTTP server in the background.

kierans
  • 2,034
  • 1
  • 16
  • 43