Uncaught server error: java.lang.NoClassDefFoundError implementing a custom provider for an external mysql database

Hi all,
I am using the latest keycloak server 21.1.1 and i am implementing a custom provider for communicating with an external database.
I have a factory for creating an DAO implementation from an external library. Inside the library is tested that the dao is successfully created. The dao implementation has injected a mysqldatasource.

I successfully find the custom provider and is successfully configured with the properties regarding the database.

I have confirmed that the datasource has been successfully created by the properties, but once i try to create the DAO via factory i get the following error “Uncaught server error: java.lang.NoClassDefFoundError:”.

I use the following dependencies:

The issue is that the code for the external library is not included into the jar. What is the best approach to include the implementation into the jar?

you can either provide the jar dependency along with your custom code in the providers folder or include dependencies inside the jar.

I leave the solution i had with gradle 7.4.0 and keycloak version 21.1.1

plugins {
id(“com.github.johnrengelman.shadow”) version “7.1.2”

apply plugin: ‘com.github.johnrengelman.shadow’

shadowJar {

dependencies {

// list of the dependencies needs to be included in the fat jar



docker file
in the gradlew command added the shadowJar
and copied the xxxxx-all.jar file to the binaries of the keycloak with the name xxxxx.jar in order to have the jar with the same name with the custom provider.

Thank you for your responses.