apply plugin: 'groovy'
apply plugin: 'idea'

configurations {
  functTestCompile.extendsFrom testCompile
  functTestRuntime.extendsFrom testRuntime
}

dependencies {
  functTestCompile libs.functionalTest
}

sourceSets {
  functionalTest {
    resources.srcDir file('src/functionalTest/resources')
    compileClasspath = sourceSets.main.output + configurations.functTestCompile
    runtimeClasspath = output + compileClasspath + configurations.functTestRuntime
    groovy {
      srcDir 'src/functionalTest/groovy'
    }
  }
}

ext {
  functionalTestReportDir = file("$test.reports.html.destination/functional")
  functionalTestResultsDir = file("$test.reports.junitXml.destination/functional")
}


task functionalTest(type: Test) {
  testClassesDir = sourceSets.functionalTest.output.classesDir
  classpath = sourceSets.functionalTest.runtimeClasspath
  reports.html.destination = functionalTestReportDir
  reports.junitXml.destination = functionalTestResultsDir
}

// lazy as plugin not applied yet - get idea to see the source folders and external dependencies
plugins.withType(org.gradle.plugins.ide.idea.IdeaPlugin) {
  idea {
    module {
      testSourceDirs += sourceSets.functionalTest.groovy.srcDirs
      testSourceDirs += sourceSets.functionalTest.resources.srcDirs
      scopes.TEST.plus.add(configurations.functTestCompile)
      scopes.TEST.plus.add(configurations.functTestRuntime)
    }
  }
}