/*
 * 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.
 */
plugins { id 'org.apache.beam.module' }
applyJavaNature(
        automaticModuleName: 'org.apache.beam.sdk.io.iceberg.hive',
        exportJavadoc: false,
        publish: false, // it's an intermediate jar for io-expansion-service
)

description = "Apache Beam :: SDKs :: Java :: IO :: Iceberg :: Hive"
ext.summary = "Runtime dependencies needed for Hive catalog integration."

def hive_version = "3.1.3"
def hbase_version = "2.6.3-hadoop3"
def hadoop_version = "3.4.1"
def iceberg_version = "1.6.1"
def avatica_version = "1.25.0"
def calcite_version = "1.37.0"

dependencies {
    // dependencies needed to run with iceberg's hive catalog
    // these dependencies are going to be included in io-expansion-service
    runtimeOnly ("org.apache.iceberg:iceberg-hive-metastore:$iceberg_version")
    // analyzeClassesDependencies fails with "Cannot accept visitor on URL", likely the plugin does not recognize "core" classifier
    // use "core" classifier to depend on un-shaded jar
    runtimeOnly ("org.apache.hive:hive-exec:$hive_version:core") {
        // old hadoop-yarn-server-resourcemanager contains critical log4j vulneribility
        exclude group: "org.apache.hadoop", module: "hadoop-yarn-server-resourcemanager"
        // old hadoop-yarn-server-resourcemanager contains critical log4j and hadoop vulneribility
        exclude group: "org.apache.hbase", module: "hbase-client"
        // old calcite avatica leaks old protobuf-java
        exclude group: "org.apache.calcite.avatica", module: "avatica"
        // old calcite vulnerabilities
        exclude group: "org.apache.calcite", module: "calcite-core"
        exclude group: "org.apache.calcite", module: "calcite-druid"
    }
    runtimeOnly ("org.apache.hadoop:hadoop-yarn-server-resourcemanager:$hadoop_version")
    runtimeOnly ("org.apache.hbase:hbase-client:$hbase_version")
    runtimeOnly ("org.apache.calcite.avatica:avatica-core:$avatica_version")
    // these exlusions were inherit from hive-exec-3.1.3.pom
    runtimeOnly ("org.apache.calcite:calcite-core:$calcite_version") {
        exclude group: "net.hydromatic", module: "aggdesigner-algorithm"
        exclude group: "org.hsqldb", module: "hsqldb"
        exclude group: "com.fasterxml.jackson.core", module: "*"
        exclude group: "org.apache.calcite.avatica", module: "avatica-core"
    }
    runtimeOnly ("org.apache.calcite:calcite-druid:$calcite_version") {
        exclude group: "com.fasterxml.jackson.core", module: "*"
        exclude group: "org.apache.calcite.avatica", module: "avatica-core"
    }
    runtimeOnly ("org.apache.hive:hive-metastore:$hive_version")
}

configurations.all {
    // the fatjar "parquet-hadoop-bundle" conflicts with "parquet-hadoop" used by org.apache.iceberg:iceberg-parquet
    exclude group: "org.apache.parquet", module: "parquet-hadoop-bundle"
}
