// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.

apply plugin: "scala"
apply plugin: "java-library"
apply from: "$rootDir/gradle/shadow.gradle"

dependencies {
  // Note: We don't use the shaded version, so we can control the dependencies.
  implementation(project(path: ":kudu-backup-common")) {
    // Ensure we use the hadoop-client provided by Spark to avoid any compatibility issues.
    exclude group: "org.apache.hadoop", module: "hadoop-common"
    // Ensure we use the scala-library provided by Spark to avoid any compatibility issues.
    exclude group: "org.scala-lang", module: "scala-library"
  }
  implementation project(path: ":kudu-client", configuration: "shadow")
  implementation project(path: ":kudu-spark", configuration: "shadow")
  implementation libs.protobufJava
  implementation (libs.scopt)  {
    // Make sure wrong Scala version is not pulled in.
    exclude group: "org.scala-lang", module: "scala-library"
  }
  // TODO(KUDU-2500): Spark uses reflection which requires the annotations at runtime.
  implementation libs.yetusAnnotations

  compileOnlyApi libs.scalaLibrary
  compileOnlyApi libs.sparkAvro
  compileOnlyApi libs.sparkCore
  compileOnlyApi libs.sparkSql
  compileOnlyApi libs.slf4jApi

  testImplementation project(path: ":kudu-test-utils", configuration: "shadow")
  testImplementation project(path: ":kudu-spark", configuration: "test")
  // Note: both configurations are needed to ensure that the classpath is correct
  testImplementation project(path: ":kudu-spark")
  testImplementation libs.junit
  testImplementation libs.log4jApi
  testImplementation libs.log4jCore
  testImplementation libs.log4jSlf4jImpl
  testImplementation libs.scalatest
  testImplementation libs.logCaptor

  // Have to re-define some dependencies here, as compile-only dependencies
  // are not inherited by the test classpath.
  // See: https://blog.gradle.org/introducing-compile-only-dependencies
  // Note: compileUnshaded is extended from the compileOnly dependency scope.
  testImplementation libs.scalaLibrary
  testImplementation(libs.sparkAvro) {
    exclude group: "org.apache.logging.log4j"
  }
  testImplementation( libs.sparkCore) {
    exclude group: "org.apache.logging.log4j"
  }
  testImplementation(libs.sparkSql) {
    exclude group: "org.apache.logging.log4j"
  }
  testImplementation libs.slf4jApi
}

shadowJar {
  dependencies {
    exclude(dependency(libs.jsr305))
    exclude(dependency("log4j:log4j::.*"))
    exclude(dependency("com.fasterxml.jackson.core::.*"))
    exclude(dependency("org.apache.arrow::.*"))
    exclude(dependency("org.apache.avro::.*"))
    exclude(dependency("org.apache.curator::.*"))
    exclude(dependency("org.apache.hadoop::.*"))
    exclude(dependency("org.apache.ivy:ivy::.*"))
    exclude(dependency("org.apache.logging.log4j::.*"))
    exclude(dependency("org.apache.parquet::.*"))
    exclude(dependency("org.apache.spark::.*"))
    exclude(dependency("org.codehaus.janino::.*"))
    exclude(dependency("org.glassfish.jersey.core::.*"))
    exclude(dependency("joda-time::.*"))
    exclude(dependency("org.scala-lang::.*"))
    exclude(dependency("org.xerial.snappy::.*"))
  }
  exclude '**/*.adoc'
  exclude '**/*.default'
  exclude '**/*.dll'
  exclude '**/*.dylib'
  exclude '**/*.html'
  exclude '**/*.md'
  exclude 'META-INF/services/**'
  exclude 'codegen/**'
  exclude 'assets/**'
  exclude 'org/threeten/**'
  exclude 'org/apache/arrow/**'
  exclude 'org/apache/orc/**'
  exclude 'javax/**'
  exclude 'org/jetbrains/**'

  minimize()
}

// Adjust the artifact name to match the maven build.
archivesBaseName = "kudu-backup${versions.sparkBase}_${versions.scalaBase}"

// kudu-backup has no public Javadoc.
javadoc {
  enabled = false
}