buildscript {
  dependencies {
    classpath "org.jetbrains.dokka:dokka-gradle-plugin:0.9.18"
  }

  repositories {
    mavenLocal()
    jcenter()
  }
}

plugins {
  id 'com.gradle.build-scan' version '2.1'
  id "org.jetbrains.kotlin.jvm" version "1.3.72"
}

allprojects {
  apply from: "$rootDir/gradle/deps.gradle"

  repositories {
    jcenter()
  }
}

subprojects {
  if (!['sampleapp', 'kales-cli'].contains(name)) {
    apply from: "$rootDir/gradle/publish.gradle"
  }

  apply plugin: 'org.jetbrains.dokka'

  configurations {
    ktlint
  }

  dokka {
    outputFormat = 'html'
    outputDirectory = "${rootDir}/website/static/api"
  }

  dependencies {
    ktlint 'com.pinterest:ktlint:0.33.0'
  }

  task ktlint(type: JavaExec, group: "verification") {
    description = "Check Kotlin code style."
    main = "com.pinterest.ktlint.Main"
    classpath = configurations.ktlint
    args "src/**/*.kt"
    // to generate report in checkstyle format prepend following args:
    // "--reporter=plain", "--reporter=checkstyle,output=${buildDir}/ktlint.xml"
    // see https://github.com/pinterest/ktlint#usage for more
  }
  check.dependsOn ktlint

  task ktlintFormat(type: JavaExec, group: "formatting") {
    description = "Fix Kotlin code style deviations."
    main = "com.pinterest.ktlint.Main"
    classpath = configurations.ktlint
    args "-F", "src/**/*.kt"
  }
}

buildScan {
  termsOfServiceUrl = "https://gradle.com/terms-of-service"
  termsOfServiceAgree = "yes"
}