# Migration of integration test task to 4.0-milestone-2

**URL:** https://discuss.gradle.org/t/migration-of-integration-test-task-to-4-0-milestone-2/22806
**Category:** Help/Discuss
**Created:** [May 30, 2017, 8:35am UTC](https://discuss.gradle.org/t/migration-of-integration-test-task-to-4-0-milestone-2/22806 "2017-05-30T08:35:53Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![robertoestivill](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/robertoestivill/32/6197_2.png) [@robertoestivill](https://discuss.gradle.org/u/robertoestivill)
#### Post date: [May 30, 2017, 8:35am UTC](https://discuss.gradle.org/t/migration-of-integration-test-task-to-4-0-milestone-2/22806/1 "2017-05-30T08:35:53Z")

</div>

I am migrating a Java library to Gradle `4.0-milestone2` and I encountered some issues with the integration task defined below.

This task allows me to have two different source directories `src/test` and `src/integration` and have separate gradle tasks to run them, `./gradlew test` and `./gradlew integration`.

Contents of `integration.gradle`

```
sourceSets {
  integration {
    java {
      compileClasspath += main.output + test.output
      runtimeClasspath += main.output + test.output
      srcDir file('src/integration/java')
    }
    resources.srcDir file('src/integration/resources')
  }
}
configurations {
  integrationCompile.extendsFrom testCompile
  integrationRuntime.extendsFrom testRuntime
}
idea {
  module {
    testSourceDirs += file('src/integration/java')
    scopes.TEST.plus += [configurations.integrationCompile]
  }
}
task integration(type: Test) {
  testClassesDir = sourceSets.integration.output.classesDir
  classpath = sourceSets.integration.runtimeClasspath
}

integration.mustRunAfter test

```

Contents of `build.gradle`

```
apply plugin: 'java-library'
apply plugin: 'idea'

apply from: './integration.gradle'

targetCompatibility = '1.7'
sourceCompatibility = '1.7'

dependencies {

  api 'com.github.ihsanbal:LoggingInterceptor:2.0.0'
  api 'com.squareup.okhttp3:okhttp-urlconnection:3.2.0'
  api 'com.squareup.retrofit2:retrofit:2.0.2'
  api 'com.squareup.retrofit2:converter-gson:2.0.2'
  api 'com.squareup.retrofit2:adapter-rxjava:2.0.2'

  testImplementation 'junit:junit:4.12'
}

test {
  testLogging.showStandardStreams = true
}

task copyTestResources(type: Copy) {
  from sourceSets.test.resources
  into sourceSets.test.output.classesDir
}
processTestResources.dependsOn copyTestResources

```

There are two problems with this configuration.

1. `copyTestResources` task does not work as `classesDir` is deprecated and `classesDirs` is not compatible.

2. The classpaths are not including the library dependencies.  
Compilation fails full of the following errors

What would be the equivalent on 4.0-m2 ?  
Thanks for your help 🙂

---

<div class="post-metadata">

### Author: ![st\_oehme](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/st_oehme/32/5249_2.png) [@st\_oehme](https://discuss.gradle.org/u/st_oehme)
#### Post date: [May 30, 2017, 10:34am UTC](https://discuss.gradle.org/t/migration-of-integration-test-task-to-4-0-milestone-2/22806/2 "2017-05-30T10:34:42Z")

</div>

You’re missing `integrationImplementation.extendsFrom(testImplementation)` and `integrationRuntimeOnly.extendsFrom(testRuntimeOnly)`. Btw if you are not going to use the old `compile`/`runtime` anymore, then you can skip those two `extends` relationships instead.

---

<div class="post-metadata">

### Author: ![st\_oehme](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/st_oehme/32/5249_2.png) [@st\_oehme](https://discuss.gradle.org/u/st_oehme)
#### Post date: [May 30, 2017, 10:36am UTC](https://discuss.gradle.org/t/migration-of-integration-test-task-to-4-0-milestone-2/22806/3 "2017-05-30T10:36:08Z")

</div>

> [@robertoestivill](#):
>
> copyTestResources task does not work as classesDir is deprecated and classesDirs is not compatible.

You shouldn’t be doing that. The classes dir is for classes, not resources.

Instead you should have `integration.runtimeClasspath += integration.output`

---

<div class="post-metadata">

### Author: ![robertoestivill](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/robertoestivill/32/6197_2.png) [@robertoestivill](https://discuss.gradle.org/u/robertoestivill)
#### Post date: [May 30, 2017, 12:10pm UTC](https://discuss.gradle.org/t/migration-of-integration-test-task-to-4-0-milestone-2/22806/4 "2017-05-30T12:10:35Z")

</div>

@st_oehme thanks for the tips.  
The following indeed worked from the command line:

`build.gradle`

```gradle
apply plugin: 'java-library'
apply plugin: 'idea'

apply from: './integration.gradle'

targetCompatibility = '1.7'
sourceCompatibility = '1.7'

dependencies {

  api 'com.github.ihsanbal:LoggingInterceptor:2.0.0'
  api 'com.squareup.okhttp3:okhttp-urlconnection:3.2.0'
  api 'com.squareup.retrofit2:retrofit:2.0.2'
  api 'com.squareup.retrofit2:converter-gson:2.0.2'
  api 'com.squareup.retrofit2:adapter-rxjava:2.0.2'

  testImplementation 'junit:junit:4.12'
}

test {
  testLogging.showStandardStreams = true
}

```

`integration.gradle`

```gradle
sourceSets {
  integration {
    java {
      compileClasspath += main.output + test.output
      runtimeClasspath += main.output + test.output
      srcDir file('src/integration/java')

      integration.runtimeClasspath += integration.output
    }
    resources.srcDir file('src/integration/resources')
  }
}
configurations {
  integrationImplementation.extendsFrom testImplementation
  integrationRuntimeOnly.extendsFrom testRuntimeOnly
}
idea {
  module {
    testSourceDirs += file('src/integration/java')
    scopes.TEST.plus += [configurations.integrationImplementation]
  }
}
task integration(type: Test) {
  testClassesDirs += sourceSets.integration.output.classesDirs
  classpath = sourceSets.integration.runtimeClasspath
}
integration.mustRunAfter test

```

However there’s an issue when syncing AndroidStudio/Intellij related to the `integrationImplementation` clause

```gradle
Error: Resolving configuration 'integrationImplementation' directly is not allowed

```

Any idea on this one?  
Thanks again

---

<div class="post-metadata">

### Author: ![st\_oehme](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/st_oehme/32/5249_2.png) [@st\_oehme](https://discuss.gradle.org/u/st_oehme)
#### Post date: [May 30, 2017, 12:44pm UTC](https://discuss.gradle.org/t/migration-of-integration-test-task-to-4-0-milestone-2/22806/5 "2017-05-30T12:44:24Z")

</div>

> [@robertoestivill](#):
>
> scopes.TEST.plus += [configurations.integrationImplementation]

That’s the culprit. Resolving the `implementation` configuration directly is meaningless, as its dependencies are used in different contexts and thus Gradle could not decide how to resolve it (for compile usage or for runtime usage). Instead add `integrationRuntimeClasspath` and `integrationCompileClasspath` to the IDE classpath.

---

<div class="post-metadata">

### Author: ![robertoestivill](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/robertoestivill/32/6197_2.png) [@robertoestivill](https://discuss.gradle.org/u/robertoestivill)
#### Post date: [May 30, 2017, 1:00pm UTC](https://discuss.gradle.org/t/migration-of-integration-test-task-to-4-0-milestone-2/22806/6 "2017-05-30T13:00:21Z")

</div>

@st_oehme nailed it one more time 🙂

The following line did the trick.

```gradle
scopes.TEST.plus += [configurations.integrationRuntimeClasspath, configurations.integrationCompileClasspath]

```

A little bit outside the original topic but still related, would anyone know why with this integration test configuration, Intellij/AndroidStudio is not able to detect Tests when running it from inside the IDE ?

It executes, but fails with the error `Empty test suite.`

Thanks again!
