buildscript {
  ext {
    javaVersion = "1.8"
    vavrVersion = "0.9.2"
    slf4jVersion = "1.7.25"
    lombokVersion = "1.16.20"
    junitJupiterVersion = "5.0.2"
    junitPlatformVersion = "1.0.2"
  }
  repositories {
    mavenLocal()
    mavenCentral()
  }
  dependencies {
    classpath "org.junit.platform:junit-platform-gradle-plugin:$junitPlatformVersion"
  }
}

plugins {
  id "idea"
  id "java"
  id "eclipse"
  id "application"
  id "maven-publish"
  id "com.github.johnrengelman.shadow" version "2.0.2"
  id "com.avast.gradle.docker-compose" version "0.6.13"
}

apply plugin: "org.junit.platform.gradle.plugin"

group = "daggerok"
version = "0.0.1"
sourceCompatibility = targetCompatibility = "$javaVersion"

mainClassName = "daggerok.App"
shadowJar.mustRunAfter jar

publishing {
  publications {
    shadow(MavenPublication) { publication ->
      project.shadow.component(publication)
    }
  }
  repositories {
    maven {
      url "$buildDir/maven-publish"
    }
  }
}

defaultTasks "clean", "build", "installDist", "distZip", "publish"

repositories {
  mavenLocal()
  mavenCentral()
}

compileJava.dependsOn(processResources)

dependencies {

  compile "io.vavr:vavr:$vavrVersion"

  compile "org.slf4j:slf4j-api:$slf4jVersion"
  // compile "org.slf4j:slf4j-jdk14:$slf4jVersion"
  compile "org.slf4j:jul-to-slf4j:$slf4jVersion"
  compile "org.slf4j:log4j-over-slf4j:$slf4jVersion"
  compile "ch.qos.logback:logback-classic:1.2.3"
  annotationProcessor "org.projectlombok:lombok:$lombokVersion"

  // junit 4
  testCompile "junit:junit:4.12"
  // junit 5
  testImplementation("org.junit.jupiter:junit-jupiter-api:$junitJupiterVersion")
  // hamcrest asserts, like: assertThat
  testImplementation("org.hamcrest:hamcrest-core:1.3")

  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")
  //testCompileOnly("org.projectlombok:lombok:$lombokVersion")
}

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
  }
}
