plugins {
  id 'application'
  id 'com.github.johnrengelman.shadow' version '5.1.0'
  id "org.jetbrains.kotlin.jvm"
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
  kotlinOptions {
    jvmTarget = "1.8"
  }
}

jar {
  manifest {
    attributes 'Version': VERSION
  }
}

distributions {
  main {
    baseName = 'kales'
  }
}

startScripts {
  applicationName = 'kales'
}

test {
  systemProperty("KALES_VERSION", VERSION)
  def rootProjPath = rootProject.projectDir.absolutePath
  // When running tests, we inject the local path to a Kales Shadow jar to be used for bootstrapping
  // test gradle projects. This is so we can test it against local current version of the code
  // instead of downloading the latest from Maven Central.
  // This also means we need to run the Gradle kales:shadowJar task before being able to run
  // kales-cli tests.
  systemProperty('KALES_FAT_JAR_PATH', "${rootProjPath}/kales/build/libs/kales-${VERSION}-all.jar")
}

mainClassName = 'kales.cli.CliKt'

project.ext.artifact = 'kales-cli'

dependencies {
  implementation 'com.github.ajalt:clikt:1.6.0'
  implementation 'com.squareup:kotlinpoet:1.3.0'
  implementation project(":activerecord")
  implementation project(":activemodel")
  implementation project(":actionpack")
  implementation project(":actionview")
  implementation "org.jetbrains.kotlin:kotlin-compiler-embeddable:$kotlinVersion"
  implementation "org.jetbrains.kotlin:kotlin-script-runtime:$kotlinVersion"
  implementation "org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable:$kotlinVersion"
  implementation "org.jetbrains.kotlin:kotlin-script-util:$kotlinVersion"
  runtime "org.jdbi:jdbi3-postgres:$jdbiVersion"
  runtime "org.postgresql:postgresql:42.2.6.jre7"
  testRuntime "com.h2database:h2:$h2DBVersion"
  testImplementation "com.google.truth:truth:$truthVersion"
  testImplementation "org.jdbi:jdbi3-core:$jdbiVersion"
  testImplementation "org.jdbi:jdbi3-kotlin:$jdbiVersion"
  testImplementation gradleTestKit()
}