import org.ajoberstar.grgit.Grgit
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
  id "com.android.tools.build" apply false
  id 'net.ltgt.errorprone' apply false
  id "com.google.devtools.ksp" apply false
  id "org.ajoberstar.grgit" apply false
  id "org.jetbrains.kotlin.jvm" apply false
  id "com.vanniktech.maven.publish" apply false
  id "org.jetbrains.dokka" apply false
  id "androidx.baselineprofile" apply false
  id "org.jetbrains.kotlinx.binary-compatibility-validator" apply false
}

allprojects {
  def compileJavaVersion = JavaVersion.VERSION_17
  def targetJavaVersion = JavaVersion.VERSION_17
  pluginManager.withPlugin("java") {
    java {
      toolchain {
        languageVersion.set(JavaLanguageVersion.of(compileJavaVersion.majorVersion))
      }
    }
    tasks.withType(JavaCompile).configureEach {
      options.release.set(targetJavaVersion.majorVersion)
    }
  }
  pluginManager.withPlugin("org.jetbrains.kotlin.android") {
    kotlin {
      jvmToolchain(compileJavaVersion.majorVersion.toInteger())
    }
    tasks.withType(KotlinCompile).configureEach {
      kotlinOptions.jvmTarget = targetJavaVersion.toString()
    }
  }
}

ext {
  git = Grgit.open(currentDir: project.rootDir)
  gitSha = git.head().id
  gitBranch = git.branch.current().name
}

tasks.register('clean', Delete) {
  delete rootProject.buildDir
}
