buildscript {
  ext {
    javaVersion = "1.8"
    vavrVersion = "0.9.2"
    kotlinVersion = "1.2.31"
    springCloudVersion = "Finchley.M9"
    springBootVersion = "2.0.1.RELEASE"
    hibernateCoreVersion = "4.2.18.Final"
    junitPlatformVersion = "1.0.2"
    junitJupiterVersion = "5.0.2"
  }
  repositories {
    mavenLocal()
    mavenCentral()
  }
  dependencies {
    classpath("org.junit.platform:junit-platform-gradle-plugin:$junitPlatformVersion")
  }
}

plugins {
  id "idea"
  id "java"
  id "maven"
  id "eclipse"
  id "org.jetbrains.kotlin.jvm" version "1.2.31"
  id "org.springframework.boot" version "2.0.1.RELEASE"
  id "com.avast.gradle.docker-compose" version "0.6.13"
  id "org.jetbrains.kotlin.plugin.spring" version "1.2.31"
  id "io.spring.dependency-management" version "1.0.5.RELEASE"
}

apply plugin: "org.junit.platform.gradle.plugin"

group = "daggerok"
version = "0.0.1"
sourceCompatibility = targetCompatibility = "$javaVersion"

compileKotlin {
  incremental = true
  kotlinOptions {
    freeCompilerArgs = ["-Xjsr305=strict"]
    jvmTarget = "$javaVersion"
  }
}

compileTestKotlin {
  incremental = true
  kotlinOptions {
    freeCompilerArgs = ["-Xjsr305=strict"]
    jvmTarget = "$javaVersion"
  }
}

defaultTasks "clean", "build"

repositories {
  mavenLocal()
  mavenCentral()
}

compileJava.dependsOn(processResources)

dependencies {

  // spring-boot
  compile("org.springframework.boot:spring-boot-starter-webflux")
  compile("org.springframework.boot:spring-boot-starter-actuator")
  //runtime("org.springframework.boot:spring-boot-devtools")
  //annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")

  //// JPA (+embedded)
  //runtime("com.h2database:h2")
  //compile("org.springframework.boot:spring-boot-starter-data-jpa")
  //compile("org.springframework.boot:spring-boot-starter-data-rest")
  //// @Id UUID
  //compile("org.hibernate:hibernate-core:$hibernateCoreVersion")

  //// Mongo (+embedded)
  //compile("org.springframework.boot:spring-boot-starter-data-mongodb-reactive")
  //compile("de.flapdoodle.embed:de.flapdoodle.embed.mongo")

  //// Kafka (+embedded)
  //compile("org.springframework.cloud:spring-cloud-stream")
  //compile("org.springframework.cloud:spring-cloud-stream-binder-kafka")
  //compile("org.springframework.kafka:spring-kafka")
  //compile("org.springframework.kafka:spring-kafka-test")
  //testCompile("org.springframework.cloud:spring-cloud-stream-test-support")

  // In java we trust...
  //compile("io.vavr:vavr:$vavrVersion")
  //annotationProcessor("org.projectlombok:lombok")
  ////testCompileOnly("org.projectlombok:lombok")

  // Kotlin
  compile("com.fasterxml.jackson.module:jackson-module-kotlin:2.9.5")
  compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion")
  compile("org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion")

  //testCompile("org.jetbrains.kotlin:kotlin-test:$kotlinVersion")
  testCompile("org.jetbrains.kotlin:kotlin-junit-test:$kotlinVersion")

  testCompile("org.springframework.boot:spring-boot-starter-test")
  testCompile("io.projectreactor:reactor-test")

  // junit 4
  testCompile "junit:junit:4.12"
  testImplementation("org.hamcrest:hamcrest-core:1.3")

  // junit 5
  testImplementation("org.junit.jupiter:junit-jupiter-api:$junitJupiterVersion")
  testRuntime("org.junit.jupiter:junit-jupiter-api:$junitJupiterVersion")
  testRuntime("org.junit.jupiter:junit-jupiter-engine:$junitJupiterVersion")
  testRuntime("org.junit.vintage:junit-vintage-engine:4.12.3")

  // IDEA (older bundle):
  testRuntime("org.junit.platform:junit-platform-launcher:$junitPlatformVersion")
  testCompileOnly('org.apiguardian:apiguardian-api:1.0.0')
}

dependencyManagement {
  imports {
    mavenBom "org.springframework.boot:spring-boot-dependencies:$springBootVersion"
    //mavenBom "org.springframework.cloud:spring-cloud-dependencies:$springCloudVersion"
  }
}

bootJar {
  launchScript()
}

def profile = project.hasProperty("profile") ? project.getProperty("profile") : "gradle"

dockerCompose {
  useComposeFiles = [project.file("docker-compose-${profile}.yaml")]
  // captureContainersOutput = true
  captureContainersOutput = false
  stopContainers = true
  removeContainers = true
  removeImages = "Local"
  removeVolumes = true
  removeOrphans = true
  forceRecreate = true
  waitForTcpPorts = false
  projectName = project.name
}

composeUp.dependsOn assemble

task wrapper(type: Wrapper) {
  gradleVersion = "4.6"
  distributionType = "ALL"
}

test {
  systemProperties "property": "value"
}

idea {
  module {
    downloadSources = true
  }
}

eclipse {
  classpath {
    downloadSources = true
  }
}
