plugins {
  id 'scala'
  id 'maven-publish'
  id 'signing'
  id "com.vanniktech.maven.publish.base"
}

repositories {
  mavenCentral()
  mavenLocal()
  maven {
    url "https://repository.mulesoft.org/nexus/content/repositories/public/"
  }
  maven {
    url "https://linkedin.jfrog.io/artifactory/open-source/" // GMA, pegasus
  }

}

configurations {
  // configuration that holds jars to include in the jar
  extraLibs

  // Dependencies that will be provided at runtime in the cloud execution
  provided

  compileOnly.extendsFrom(provided)
  testImplementation.extendsFrom provided
}

configurations.all {
  resolutionStrategy.force "org.antlr:antlr4-runtime:4.8"
  resolutionStrategy.force "org.antlr:antlr4-tool:4.8"
}

dependencies {
  implementation project(":feathr-compute")
  implementation project(":feathr-config")
  implementation project(":feathr-data-models")
  implementation project(path: ':feathr-data-models', configuration: 'dataTemplate')
  // needed to include data models in jar
  extraLibs project(path: ':feathr-data-models', configuration: 'dataTemplate')
  implementation spec.product.scala.scala_library

  implementation spec.product.jackson.dataformat_csv
  implementation spec.product.jackson.dataformat_yaml
  implementation spec.product.jackson.module_scala
  implementation spec.product.jackson.dataformat_hocon
  implementation spec.product.jackson.jackson_core
  implementation spec.product.spark_redis
  implementation spec.product.fastutil
  implementation spec.product.hadoop.mapreduce_client_core
  implementation spec.product.mvel
  implementation spec.product.jackson.jackson_module_caseclass
  implementation spec.product.protobuf
  implementation spec.product.guava
  implementation spec.product.xbean
  implementation spec.product.json
  implementation spec.product.antlr
  implementation spec.product.antlrRuntime

  implementation spec.product.jackson.jackson_databind
  provided spec.product.avroUtil
  provided spec.product.typesafe_config
  provided spec.product.log4j
  provided spec.product.hadoop.common
  provided(spec.product.spark.spark_core) {
    exclude group: 'org.apache.xbean', module: 'xbean-asm6-shaded'
  }
  provided(spec.product.spark.spark_avro) {
    exclude group: 'org.apache.xbean', module: 'xbean-asm6-shaded'
  }
  provided(spec.product.spark.spark_hive) {
    exclude group: 'com.tdunning', module: 'json'
  }
  provided spec.product.spark.spark_sql

  testImplementation spec.product.equalsverifier
  testImplementation spec.product.spark.spark_catalyst
  testImplementation spec.product.mockito
  testImplementation spec.product.scala.scalatest
  testImplementation spec.product.testing
  testImplementation spec.product.jdiagnostics
}

// Since there are cross-calls from Scala to Java, we use joint compiler
// to compile them at the same time with Scala compiler.
// See https://docs.gradle.org/current/userguide/scala_plugin.html
sourceSets {
  main {
    scala {
      srcDirs = ['src/main/scala', 'src/main/java']
    }
    java {
      srcDirs = []
    }
  }
  test {
    scala {
      srcDirs = ['src/test/scala', 'src/test/java']
    }
    java {
      srcDirs = []
    }
  }
}

test {
  useTestNG()
}


java {
  withSourcesJar()
  withJavadocJar()
}

tasks.withType(Javadoc) {
  options.addStringOption('Xdoclint:none', '-quiet')
  options.addStringOption('encoding', 'UTF-8')
  options.addStringOption('charSet', 'UTF-8')
}

// Required for publishing to local maven
publishing {
  publications {
    mavenJava(MavenPublication) {
      artifactId = 'feathr-impl'
      from components.java
      versionMapping {
        usage('java-api') {
          fromResolutionOf('runtimeClasspath')
        }
        usage('java-runtime') {
          fromResolutionResult()
        }
      }
    }
  }
}
