java.lang.NoClassDefFoundError: com/mongodb/client/MongoClients

Hello, ive been making a minecraft plugin using a MongoDB database and maven for a while but today i had to swap from maven to gradle and i keep getting this java.lang.NoClassDefFoundError: com/mongodb/client/MongoClients error when trying to connect to my database when the server starts. ive looked around for a while and cant find any working solutions. The MongoDB dependencies are in the compileClasspath, runtimeClasspath and external libraries. i did notice that the maven build was made bigger when adding MongoDB but the gradle build was not. I made a small test plugin that still has the same issue, this is the entire code of the plugin

package com.quackertin.databasetest;

import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import org.bson.Document;
import org.bukkit.plugin.java.JavaPlugin;

public final class DatabaseTest extends JavaPlugin {

    @Override
    public void onEnable() {

        String test = "my MongoDB database login";

        MongoClient mongoClient = MongoClients.create(test);
        MongoDatabase database = mongoClient.getDatabase("PlayerData");
        MongoCollection<Document> collection = database.getCollection("PlayerSkillsData");

        collection.find().forEach(document -> {
            System.out.println(document.toJson());
        });
    }
}

the only other added code is the MongoDB implementation in my build.gradle.
I feel like my build.gradle is messed up since the plugin doesnt become larger after adding MongoDB like it does with maven but im not sure. Any and all help is greatly appreciated :smiley:

Please try with below dependency in your POM if your MongoDB version is 7.x.

<dependency>
        <groupId>org.mongodb</groupId>
        <artifactId>mongodb-driver-sync</artifactId>
        <version>4.11.0</version>
</dependency>

If you have the same error after this change, post your POM file here and let us know the MongoDB version you are connecting to.