Jump to content

NoClassDefFoundError: org/bson/conversions/Bson


Tatuck

Recommended Posts

Hello. I am trying to use MongoDB on a mod, I have written 

compile 'org.mongodb:mongodb-driver-sync:4.2.3'

in the dependencies (build.gradle), when I start the mod by starting "runClient" on IntelliJ it works perfectly. But when I drop the file generated (build/libs/name-version.jar) using "gradlew build" it shows me this error:

java.lang.NoClassDefFoundError: org/bson/conversions/Bson

What can I do? Should I import the library using other method? Which method? Thanks!

Link to comment
Share on other sites

32 minutes ago, diesieben07 said:

You can use shading as well, look at the Gradle Shadow plugin.

Okay, I have tried and it created a file larger but it doesn't work. It doesn't show up in Minecraft. Writing this in the bottom of my build.gradle file:

buildscript {
  repositories {
    maven {
      url "https://plugins.gradle.org/m2/"
    }
  }
  dependencies {
    classpath "com.github.jengelman.gradle.plugins:shadow:6.1.0"
  }
}

apply plugin: "com.github.johnrengelman.shadow"

 

Also, I have tried using Forge shading like this:

configurations {
    shade
    compile.extendsFrom shade
}
dependencies {
    minecraft 'net.minecraftforge:forge:1.16.5-36.1.0'
    shade 'org.mongodb:mongodb-driver-sync:4.2.3'
}
jar {
    manifest {
        attributes([
            ...
        ])
    }
    configurations.shade.each { dep ->
        from(project.zipTree(dep)){
            exclude 'META-INF', 'META-INF/**'
        }
    }
}

But "shade" in dependencies shows this error: "No candidates found for method call shade." 
What can I do? Thanks for you help

Link to comment
Share on other sites

On 4/8/2021 at 11:29 PM, Tatuck said:

Okay, I have tried and it created a file larger but it doesn't work. It doesn't show up in Minecraft. Writing this in the bottom of my build.gradle file:




buildscript {
  repositories {
    maven {
      url "https://plugins.gradle.org/m2/"
    }
  }
  dependencies {
    classpath "com.github.jengelman.gradle.plugins:shadow:6.1.0"
  }
}

apply plugin: "com.github.johnrengelman.shadow"

 

Also, I have tried using Forge shading like this:




configurations {
    shade
    compile.extendsFrom shade
}
dependencies {
    minecraft 'net.minecraftforge:forge:1.16.5-36.1.0'
    shade 'org.mongodb:mongodb-driver-sync:4.2.3'
}
jar {
    manifest {
        attributes([
            ...
        ])
    }
    configurations.shade.each { dep ->
        from(project.zipTree(dep)){
            exclude 'META-INF', 'META-INF/**'
        }
    }
}

But "shade" in dependencies shows this error: "No candidates found for method call shade." 
What can I do? Thanks for you help

Okay. I have tried again with shadow, I did it like it's shown here: https://github.com/Choonster-Minecraft-Mods/GradleShadowTestMod/blob/master/build.gradle but no, it doesn't work. It shows me this error: 

com.google.common.util.concurrent.ExecutionError: java.lang.NoClassDefFoundError: org/gradle/api/internal/java/JavaLibrary

What can I do?

 

UPDATE:

If it's needed, my build.gradle:

buildscript {
    repositories {
        maven { url = 'https://files.minecraftforge.net/maven' }
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '4.1.+', changing: true
        classpath 'com.github.jengelman.gradle.plugins:shadow:6.1.0'
    }
}

plugins {
    id 'com.github.johnrengelman.shadow' version '6.1.0'
    id 'java'
}

apply plugin: 'net.minecraftforge.gradle'
// Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.
apply plugin: 'eclipse'
apply plugin: 'maven-publish'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'java'

version = '1.0'
group = 'com.tatuck.coordinateslocator' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = 'tatuckcoordslocator'

java.toolchain.languageVersion = JavaLanguageVersion.of(8) // Mojang ships Java 8 to end users, so your mod should target Java 8.

println('Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + '(' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch'))
minecraft {

    mappings channel: 'official', version: '1.16.5'

    runs {
        client {
            workingDirectory project.file('run')

            property 'forge.logging.markers', 'REGISTRIES'

            property 'forge.logging.console.level', 'debug'

            mods {
                examplemod {
                    source sourceSets.main
                }
            }
        }

        server {
            workingDirectory project.file('run')

            // Recommended logging data for a userdev environment
            // The markers can be changed as needed. 
            // "SCAN": For mods scan.
            // "REGISTRIES": For firing of registry events.
            // "REGISTRYDUMP": For getting the contents of all registries.
            property 'forge.logging.markers', 'REGISTRIES'

            // Recommended logging level for the console
            // You can set various levels here.
            // Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels
            property 'forge.logging.console.level', 'debug'

            mods {
                examplemod {
                    source sourceSets.main
                }
            }
        }

        data {
            workingDirectory project.file('run')

            property 'forge.logging.markers', 'REGISTRIES'

            property 'forge.logging.console.level', 'debug'

            args '--mod', 'examplemod', '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/')

            mods {
                examplemod {
                    source sourceSets.main
                }
            }
        }
    }
}

// Include resources generated by data generators.
sourceSets.main.resources { srcDir 'src/generated/resources' }


dependencies {
    minecraft 'net.minecraftforge:forge:1.16.5-36.1.0'
    shadow 'org.mongodb:mongodb-driver-sync:4.2.3'

    // http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
    // http://www.gradle.org/docs/current/userguide/dependency_management.html

}

shadowJar {
    manifest {
        attributes([
                "Specification-Title": "examplemod",
                "Specification-Vendor": "examplemodsareus",
                "Specification-Version": "1", // We are version 1 of ourselves
                "Implementation-Title": project.name,
                "Implementation-Version": "${version}",
                "Implementation-Vendor" :"examplemodsareus",
                "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
        ])
    }
}
// Example for how to get properties into the manifest for reading by the runtime..
jar {
    manifest {
        attributes([
            "Specification-Title": "examplemod",
            "Specification-Vendor": "examplemodsareus",
            "Specification-Version": "1", // We are version 1 of ourselves
            "Implementation-Title": project.name,
            "Implementation-Version": "${version}",
            "Implementation-Vendor" :"examplemodsareus",
            "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
        ])
    }
}

// Example configuration to allow publishing using the maven-publish task
// This is the preferred method to reobfuscate your jar file
jar.finalizedBy('reobfJar') 
// However if you are in a multi-project build, dev time needs unobfed jar files, so you can delay the obfuscation until publishing by doing
//publish.dependsOn('reobfJar')

publishing {
    publications {
        mavenJava(MavenPublication) {
            artifact jar
        }
    }
    repositories {
        maven {
            url "file:///${project.projectDir}/mcmodsrepo"
        }
    }
}

UPDATE:

Also tried https://www.baeldung.com/gradle-fat-jar, it just created a bigger file which doesn't work, it doesn't show up in Minecraft mods. 

Edited by Tatuck
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.