Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

3.5 KB
Raw Blame
/*
 * 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.
 */
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

plugins {
  `maven-publish`
  id("java")
  alias(libs.plugins.shadow)
}

dependencies {
  // aliyun-sdk-oss 3.10.2 pulls in jettison 1.1. Declare it directly so that both the shaded jar
  // and the published POM resolve the version in the catalog.
  implementation(libs.jettison)
  implementation(libs.aliyun.credentials.sdk)
  implementation(libs.aliyun.sdk.oss) {
    // aliyun-sdk-oss 3.13.0 pulls aliyun-java-sdk-core 4.5.10, which depends on ini4j 0.5.4.
    // ini4j only backs the core SDK's local profile credentials provider, and OSSFileIO
    // authenticates with a static key or a session token, so keep it out of the bundle
    // (HIGH CVE-2022-41404, tracked in #14777).
    exclude(group = "org.ini4j", module = "ini4j")
  }
  // Aliyun oss SDK depends on this package, and JDK >= 9 requires manual add
  // https://www.alibabacloud.com/help/en/oss/developer-reference/java-installation?spm=a2c63.p38356.0.i1
  implementation(libs.sun.activation)
  // Include Gravitino Aliyun credential providers (OSSSecretKeyProvider, etc.) for credential vending
  implementation(project(":bundles:aliyun"))

  testImplementation(libs.junit.jupiter.api)
  testRuntimeOnly(libs.junit.jupiter.engine)
}

tasks.withType(ShadowJar::class.java) {
  isZip64 = true
  includeEmptyDirs = false
  configurations = listOf(project.configurations.runtimeClasspath.get())
  archiveClassifier.set("")

  dependencies {
    exclude(dependency("org.slf4j:slf4j-api"))
    // Exclude Gravitino modules to prevent class duplication with server classpath
    exclude(project(":api"))
    exclude(project(":common"))
    exclude(project(":catalogs:catalog-common"))
    exclude(project(":catalogs:hadoop-common"))
  }

  // :bundles:aliyun pulls Jackson into this fat jar. Relocate it so the bundle remains
  // self-contained without exposing com.fasterxml.jackson classes on the server classpath.
  relocate(
    "com.fasterxml.jackson",
    "org.apache.gravitino.iceberg.aliyun.shaded.com.fasterxml.jackson"
  )

  // POM metadata is not relocated by shadow and would still advertise the original
  // Jackson coordinates.
  exclude("META-INF/maven/com.fasterxml.jackson.core/**")
  exclude("META-INF/maven/com.fasterxml.jackson.datatype/**")
  exclude("META-INF/maven/com.fasterxml.jackson.module/**")
  exclude("META-INF/maven/com.fasterxml.jackson/**")

  mergeServiceFiles()
}

tasks.jar {
  dependsOn(tasks.named("shadowJar"))
  archiveClassifier.set("empty")
}

tasks.test {
  val shadowJar = tasks.named<ShadowJar>("shadowJar")
  dependsOn(shadowJar)
  inputs.file(shadowJar.flatMap { it.archiveFile })
  doFirst {
    systemProperty(
      "shadowJarPath",
      shadowJar.get().archiveFile.get().asFile.absolutePath
    )
  }
}