0

I'm using the shadowJar Gradle target provided by the com.github.johnrengelman.shadow Gradle plugin to build up an application, which requires an org.apache.hive.jdbc.HiveDriver to connect to Kudu using Impala.

The problem is that when I use standard approach to import the driver in Scala:

Class.forName("org.apache.hive.jdbc.HiveDriver")
  • the shadow plugin removes it from the resulting JAR, implying an runtime error of:
    • java.lang.ClassNotFoundException: org.apache.hadoop.hive.jdbc.HiveDriver.

My build.gradle contains:

dependencies {
  implementation {
    "org.apache.hive:hive-jdbc:1.2.1"
  }
}

How do I instruct the shadow plugin not to delete the required dependency injected via a String?

jirislav
  • 340
  • 6
  • 16

1 Answers1

0

I found out the solution is to include the static type not via Class.forName, but using code by importing it:

import java.sql.DriverManager
import org.apache.hive.jdbc.{HiveConnection, HiveDriver}

class Foo {

  // Register Hive Driver this way to prevent shadowing to cut it off
  new HiveDriver()

  DriverManager.getConnection(connectionUrl, user, password) match {
    case connection: HiveConnection =>
       ...
  }
}

This way, the shadow plugin is officially informed about the fact that the Driver is actually required.

jirislav
  • 340
  • 6
  • 16