buildscript {
  dependencies {
    classpath("com.google.cloud.tools:jib-quarkus-extension-gradle:0.1.1")
  }
}

plugins {
  id "java"
  id "io.quarkus"
  id "com.google.cloud.tools.jib" version "3.1.4"
  id "com.diffplug.spotless" version "6.1.2"
}

group = "io.opentelemetry"
version = "0.0.1-SNAPSHOT"

repositories {
  mavenCentral()
  mavenLocal()
}

spotless {
  java {
    googleJavaFormat()
    licenseHeaderFile(rootProject.file("../../../buildscripts/spotless.license.java"), "(package|import|public)")
    target("src/**/*.java")
  }
}

dependencies {
  implementation enforcedPlatform("io.quarkus.platform:quarkus-bom:2.5.0.Final")
  implementation "io.quarkus:quarkus-resteasy"
}

compileJava {
  // Quarkus 2.0+ does not support Java 8
  options.release = 11
}

def targetJDK = project.hasProperty("targetJDK") ? project.targetJDK : 11

def tag = findProperty("tag") ?: new Date().format("yyyyMMdd.HHmmSS")

jib {
  from.image = "openjdk:$targetJDK"
  to.image = "ghcr.io/open-telemetry/opentelemetry-java-instrumentation/smoke-test-quarkus:jdk$targetJDK-$tag"
  container {
    mainClass = 'bogus'  // to suppress Jib warning about missing main class
  }
  pluginExtensions {
    pluginExtension {
      implementation = 'com.google.cloud.tools.jib.gradle.extension.quarkus.JibQuarkusExtension'
    }
  }
}

tasks.jib.dependsOn quarkusBuild
tasks.jibDockerBuild.dependsOn quarkusBuild
