import com.vanniktech.maven.publish.SonatypeHost

buildscript {
  ext.junitJupiterVersion = '5.6.1'
  ext.pegasusVersion = '29.22.16'
  ext.mavenVersion = '3.6.3'
  ext.springVersion = '5.3.19'
  ext.springBootVersion = '2.5.12'
  apply from: './repositories.gradle'
  buildscript.repositories.addAll(project.repositories)
  dependencies {
    classpath 'com.linkedin.pegasus:gradle-plugins:' + pegasusVersion
  }
}

plugins {
  id 'java'
  // Currently "maven-publish" has some issues with publishing to Nexus repo. So, we will use a different plugin.
  // See https://issues.sonatype.org/browse/OSSRH-86507 for more details.
  id "com.vanniktech.maven.publish" version "0.22.0"
  id 'signing'
}

repositories {
    mavenCentral()
}

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
}

jar {
  archivesBaseName = "feathr_2.12"
  duplicatesStrategy = DuplicatesStrategy.EXCLUDE
  manifest {
    attributes('Class-Path': [project.configurations.runtimeClasspath],
        'Main-Class': 'com.linkedin.feathr.offline.job.FeatureJoinJob',
        "Implementation-title": "Build jar for local experimentation")
  }
  from {
    configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
  }
  exclude 'META-INF/*.RSA', 'META-INF/*.SF','META-INF/*.DSA'

  // Explicitly exclude com/linkedin/data and org/apache/hadoop files from the final jar. They can cause issues in other downstream applications.
  exclude 'com/linkedin/data/**'
  exclude 'org/apache/hadoop/**'
  exclude 'com/google/**'
  zip64 = true
}

dependencies {
  implementation project(":feathr-compute")
  implementation project(":feathr-config")
  implementation project(":feathr-data-models")
  implementation project(":feathr-impl")
  // needed to include data models in jar
  extraLibs project(path: ':feathr-data-models', configuration: 'dataTemplate')
  implementation 'net.snowflake:snowflake-jdbc:3.13.18'
  implementation 'net.snowflake:spark-snowflake_2.12:2.10.0-spark_3.2'
  provided 'com.microsoft.azure:azure-eventhubs-spark_2.12:2.3.21'
  provided 'com.azure.cosmos.spark:azure-cosmos-spark_3-2_2-12:4.11.1'
  provided 'com.microsoft.sqlserver:mssql-jdbc:10.2.0.jre8'
  provided 'org.eclipse.jetty:jetty-util:9.3.24.v20180605'
  provided 'org.apache.kafka:kafka-clients:3.1.0'
  provided 'org.apache.spark:spark-core_2.12:3.1.3'
  provided 'org.apache.spark:spark-sql-kafka-0-10_2.12:3.1.3'
  provided 'org.postgresql:postgresql:42.3.4'
}

ext {
  // Version numbers shared between multiple dependencies
  // FUTURE consider version catalogs https://docs.gradle.org/current/userguide/platforms.html
  ver = [
      scala   : '2.12.15',
      scala_rt: '2.12',
      spark   : '3.1.3'
  ]
}

project.ext.spec = [
    'product' : [
        'pegasus' : [
            'd2' : 'com.linkedin.pegasus:d2:29.33.3',
            'data' : 'com.linkedin.pegasus:data:29.33.3',
            'dataAvro1_6' : 'com.linkedin.pegasus:data-avro-1_6:29.33.3',
            'generator': 'com.linkedin.pegasus:generator:29.33.3',
        ],
        'jackson' : [
            'dataformat_csv' : "com.fasterxml.jackson.dataformat:jackson-dataformat-csv:2.12.6",
            'dataformat_yaml' : "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.12.6",
            'dataformat_hocon' : "com.jasonclawson:jackson-dataformat-hocon:1.1.0",
            'module_scala' : "com.fasterxml.jackson.module:jackson-module-scala_$ver.scala_rt:2.12.6",
            'jackson_databind' : "com.fasterxml.jackson.core:jackson-databind:2.12.6.1",
            'jackson_core': "com.fasterxml.jackson.core:jackson-core:2.12.6",
            'jackson_module_caseclass' : "com.github.changvvb:jackson-module-caseclass_$ver.scala_rt:1.1.1",
        ],
        'spark_redis' : "com.redislabs:spark-redis_$ver.scala_rt:3.0.0",
        'typesafe_config' : "com.typesafe:config:1.3.4",
        'hadoop' : [
            'mapreduce_client_core' : "org.apache.hadoop:hadoop-mapreduce-client-core:2.7.7",
            'common' : "org.apache.hadoop:hadoop-common:2.7.7",
        ],
        'spark' : [
            'spark_core' : "org.apache.spark:spark-core_$ver.scala_rt:$ver.spark",
            'spark_avro' : "org.apache.spark:spark-avro_$ver.scala_rt:$ver.spark",
            'spark_hive' : "org.apache.spark:spark-hive_$ver.scala_rt:$ver.spark",
            'spark_sql' : "org.apache.spark:spark-sql_$ver.scala_rt:$ver.spark",
            'spark_catalyst' : "org.apache.spark:spark-catalyst_$ver.scala_rt:$ver.spark",
            "spark_sql_kafka" : "org.apache.spark:spark-sql-kafka-0-10_$ver.scala_rt:3.1.3"
        ],
        'scala' : [
            'scala_library' : "org.scala-lang:scala-library:$ver.scala",
            'scalatest' : "org.scalatest:scalatest_$ver.scala_rt:3.0.0",
        ],
        'avro' : "org.apache.avro:avro:1.10.2",
        "avroUtil": "com.linkedin.avroutil1:helper-all:0.2.100",
        "azure": "com.microsoft.azure:azure-eventhubs-spark_2.12:2.3.21",
        'fastutil' : "it.unimi.dsi:fastutil:8.1.1",
        'mvel' : "org.mvel:mvel2:2.4.7.Final",
        'protobuf' : "com.google.protobuf:protobuf-java:2.6.1",
        'guava' : "com.google.guava:guava:25.0-jre",
        'xbean' : "org.apache.xbean:xbean-asm6-shaded:4.10",
        'log4j' : "org.apache.logging.log4j:log4j-core:2.17.2",
        'jetty': "org.eclipse.jetty:jetty-util:9.3.24.v20180605",
        'kafka': "org.apache.kafka:kafka-clients:3.1.0",

        'json' : "org.json:json:20180130",
        'sqlserver': "com.microsoft.sqlserver:mssql-jdbc:10.2.0.jre8",
        'postgresql': "org.postgresql:postgresql:42.3.4",
        'equalsverifier' : "nl.jqno.equalsverifier:equalsverifier:3.1.12",
        'mockito' : "org.mockito:mockito-core:3.1.0",
        'snowflake-jdbc' : "net.snowflake:3.13.18",
        "spark-snowflake_2.12" : "net.snowflake:2.10.0-spark_3.2",
        "mockito_inline": "org.mockito:mockito-inline:2.28.2",
        'testing' : "org.testng:testng:6.14.3",
        'jdiagnostics' : "org.anarres.jdiagnostics:jdiagnostics:1.0.7",
        "antlr": "org.antlr:antlr4:4.8",
        "antlrRuntime": "org.antlr:antlr4-runtime:4.8",
        "jsqlparser": "com.github.jsqlparser:jsqlparser:3.1",
        'common_collections': 'commons-collections:commons-collections:3.2.2',
    ]
]

if (hasProperty('buildScan')) {
  buildScan {
    termsOfServiceUrl = 'https://gradle.com/terms-of-service'
    termsOfServiceAgree = 'yes'
  }
}

allprojects {
  plugins.withId("com.vanniktech.maven.publish.base") {
    group = "com.linkedin.feathr"
    version = project.version
    mavenPublishing {
      publishToMavenCentral(SonatypeHost.DEFAULT)
      signAllPublications()
      pom {
        name = 'Feathr'
        description = 'An Enterprise-Grade, High Performance Feature Store'
        url = 'https://github.com/feathr-ai/feathr'
        licenses {
          license {
            name = 'APL2'
            url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
          }
        }
        developers {
          developer {
            id = 'feathr_dev'
            name = 'Feathr Dev'
            email = 'feathrai@gmail.com'
          }
        }
        scm {
          connection = 'scm:git@github.com:linkedin/feathr.git'
          url = 'https://github.com/feathr-ai/feathr'
        }
      }
    }
  }
}
