2

Here's my shadowJar task

shadowJar {
    archiveName "server.jar"
    mainClassName = "myapp.ApplicationKt"
    manifest {
        attributes(
                'Class-Path': project.configurations.compile.collect { it.getName() }.join(' ')
        )
    }
    minimize {
//        exclude(dependency('.*:.*:.*'))
    }
    from sourceSets.main.output
}

Note the commented exclude line removing any dependency from being minimized (effectively disabling shadowJar). When I uncomment this, then the resulting jar works. However, there seems to be some problematic dependency that shadowJar's minimize chops away that is actually loaded at runtime:

Here's the error that I keep getting:

2020-02-09 16:39:01.843 [main] INFO  ktor.application - No ktor.deployment.watch patterns specified, automatic reload is not active
Exception in thread "main" java.util.ServiceConfigurationError: org.jetbrains.exposed.sql.DatabaseConnectionAutoRegistration: Provider org.jetbrains.exposed.jdbc.ExposedConnectionImpl not found
at java.util.ServiceLoader.fail(ServiceLoader.java:239)
        at java.util.ServiceLoader.access$300(ServiceLoader.java:185)
        at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:372)
        at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
        at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
        at kotlin.collections.CollectionsKt___CollectionsKt.firstOrNull(_Collections.kt:224)
        at org.jetbrains.exposed.sql.Database.<clinit>(Database.kt:64)
        at myapp.DB.init(DB.kt:23)
        at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.instantiateAndConfigureApplication(ApplicationEngineEnvironmentReloading.kt:293)
        at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.createApplication(ApplicationEngineEnvironmentReloading.kt:137)
        at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.start(ApplicationEngineEnvironmentReloading.kt:257)
        at io.ktor.server.netty.NettyApplicationEngine.start(NettyApplicationEngine.kt:126)
        at myApp.ApplicationKt.main(Application.kt:35)
        at kotlin.coroutines.intrinsics.IntrinsicsKt__IntrinsicsJvmKt$createCoroutineUnintercepted$$inlined$createCoroutineFromSuspendFunction$IntrinsicsKt__IntrinsicsJvmKt$1.invokeSuspend(IntrinsicsJvm.kt:199)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlin.coroutines.ContinuationKt.startCoroutine(Continuation.kt:114)
        at kotlin.coroutines.jvm.internal.RunSuspendKt.runSuspend(RunSuspend.kt:19)

I use Exposed database library with mysql driver. Here's how I'm connecting to exposed database

        Database.connect(
            driver = "com.mysql.cj.jdbc.Driver",

I believe the problem is somewhere around this. It's not able to find the database driver at the runtime.

I've tried the obvious: Excluding exposed, sql, mysql-connector-java dependencies to no avail.

Aditya Anand
  • 776
  • 2
  • 9
  • 29
  • Do you repack also META-INF folder or just class files? – Tapac Feb 10 '20 at 13:01
  • Nope, not doing that yet (the shadowJar task above is pretty much all I'm doing right now). Would adding META-INF handling help? Would you be able to provide (or link to) an example of doing this? I've scavenged everything I could find in the depths of Github code search for all repos using shadowJar with exposed, haven't seen a different kind of handling anywhere (all of them basically don't even have minimize() at all) – Aditya Anand Feb 11 '20 at 13:16
  • Try to add `mergeServiceFiles()` into your `shadowJar` task: ` shadowJar { mergeServiceFiles() } ` – Tapac Feb 12 '20 at 15:23
  • Tried that, got the same error as above (`org.jetbrains.exposed.sql.DatabaseConnectionAutoRegistration: Provider org.jetbrains.exposed.jdbc.ExposedConnectionImpl not found`...) Any other ideas? – Aditya Anand Feb 13 '20 at 08:13
  • What dependencies do you pack into shadowJar? – Tapac Feb 14 '20 at 09:43
  • All of these: https://gist.github.com/AdityaAnand1/4b3e110a08bacc0a4b3bb61d6739583a – Aditya Anand Feb 14 '20 at 10:03
  • Could you share a minimal build.gradle + class with main function to test? – Tapac Feb 15 '20 at 11:12

0 Answers0