HenryFoster Posted April 28, 2019 Posted April 28, 2019 (edited) Hi, I want to add 2 additional libs to my mod (JDBC and Hibernate). I edited my buil.gradle and ran: gradlew build First try: dependencies { minecraft 'net.minecraftforge:forge:1.13.2-25.0.191' compile 'org.hibernate:hibernate-agroal:5.3.10.Final' <--- compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.15' <--- } 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") ]) } from { <--- configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } <---- } <--- } I got the fatjar but when I started the game it crashed with an unexpected error occured without a log. Is this the right way to add external libs into a forgemod? Second try: I tryed to do it like in this wiki: https://github.com/MinecraftForge/ForgeGradle/wiki/Dependencies buildscript { repositories { maven { url = 'https://files.minecraftforge.net/maven' } jcenter() mavenCentral() } dependencies { classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true } } apply plugin: 'net.minecraftforge.gradle' apply plugin: 'eclipse' apply plugin: 'maven-publish' version = '1.0' group = 'com.yourname.modid' // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = 'modid' sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' // Need this here so eclipse task generates correctly. minecraft { mappings channel: 'snapshot', version: '20180921-1.13' runs { client { workingDirectory project.file('run') property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP' property 'forge.logging.console.level', 'debug' mods { examplemod { source sourceSets.main } } } server { workingDirectory project.file('run') property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP' property 'forge.logging.console.level', 'debug' mods { examplemod { source sourceSets.main } } } } } configurations { compile } dependencies { minecraft 'net.minecraftforge:forge:1.13.2-25.0.191' compile 'org.hibernate:hibernate-agroal:5.3.10.Final' compile 'mysql:mysql-connector-java:8.0.15' } // 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") ]) } from configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } def reobfFile = file("$buildDir/reobfJar/output.jar") def reobfArtifact = artifacts.add('default', reobfFile) { type 'jar' builtBy 'reobfJar' } publishing { publications { mavenJava(MavenPublication) { artifact reobfArtifact } } repositories { maven { url "file:///${project.projectDir}/mcmodsrepo" } } } But it failed building: * What went wrong: A problem occurred evaluating root project 'TutorialMod'. > Could not resolve all files for configuration ':compile'. > Cannot resolve external dependency org.hibernate:hibernate-agroal:5.3.10.Final because no repositories are defined. Required by: project : > Cannot resolve external dependency mysql:mysql-connector-java:8.0.15 because no repositories are defined. Required by: project : > Cannot resolve external dependency net.minecraftforge:forge:1.13.2-25.0.191 because no repositories are defined. Required by: project : * Exception is: org.gradle.api.GradleScriptException: A problem occurred evaluating root project 'TutorialMod'. ... Caused by: org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all files for configuration ':compile'. ... Caused by: org.gradle.internal.resolve.ModuleVersionNotFoundException: Cannot resolve external dependency org.hibernate:hibernate-agroal:5.3.10.Final because no repositories are defined. This seems kinda strange because the repository is defined and he had no problems finding it in my first try. I gues I dont understand gradle enough. I just worked with Maven before and I used a maven-plugin there to build a jar-with-dependencies. Edited April 28, 2019 by HenryFoster Quote
HenryFoster Posted April 29, 2019 Author Posted April 29, 2019 Little update: Finally I found a way to tell gradle to build a jar with my dependencies. I also checked the final jarfile if they are really there and they are. So far so good. This is how my new build.gradle (I only copied the parts I changed compared to the default one) repositories { mavenCentral() } configurations { embed } dependencies { minecraft 'net.minecraftforge:forge:1.13.2-25.0.191' embed 'org.hibernate:hibernate-agroal:5.3.10.Final' embed group: 'mysql', name: 'mysql-connector-java', version: '8.0.15' compile 'org.hibernate:hibernate-agroal:5.3.10.Final' compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.15' } 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") ]) } from configurations.embed.collect { it.isDirectory() ? it : zipTree(it) } } I still think I did this kinda wrong because I have the dependencies 2times there. One time for compiling and onetime for embeding but I don't managed to make it work otherwise. When I start minecraft with my mod The game crashed whilst initializing game. I will add the full errorlog below. I thought that this maybe caused by my code so I removed all my classes that are using hibernate and jdbc but I get the same errorlog. crash-2019-04-29_16.30.59-client.txt Quote
Angercraft Posted April 29, 2019 Posted April 29, 2019 Instead of adding you dependencies to the one you're currently adding it do, you want to add it to the other dependencies, which is further down the file. I also recommend adding mavenCentral() to your buildscript repositories, such you have easy access to maven dependencies. I have added a pastebin for a build.gradle file I have, which adds a SQLite dependency, as an example. Just remember the file is version specific, so do not just copy paste over your own! https://pastebin.com/RpbicBaD Hope it helps. Quote
HenryFoster Posted April 29, 2019 Author Posted April 29, 2019 (edited) Ahrggh I should have posted the whole file to make it clear sorry: https://pastebin.com/AG4TNv8K I have it verry similar to yours. But when you add a dependency like this: compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.15' it works only when you start the mod from your IDE. If I build the jar it does not contain my other libs. I somehow need to tell gradle explicidly to put my two dependencies into the jar. Edited April 29, 2019 by HenryFoster Quote
Angercraft Posted May 1, 2019 Posted May 1, 2019 (edited) I tried a bit, both with a maven repository as a dependency, but also using a jdbc jar file in the root of the file, and it seems that neither of those solutions build the mod with the dependency included. I'm not sure how to solve this and perhaps someone else have a solution, as I couldn't find anyone with quite the same problem as you. Edited May 1, 2019 by Angercraft 1 Quote
Angercraft Posted May 1, 2019 Posted May 1, 2019 Okay, it seems one way to do it is, with this: https://github.com/PaleoCrafter/Dependency-Extraction-Example/tree/library-embedding Hope it works out, or someone else can answer this with more knowledge. 1 Quote
Cadiboo Posted May 1, 2019 Posted May 1, 2019 If you want them in your developer environment put them in ./libs or use maven. If you want them packaged with your mod in a production environment use forges jar-in-jar system Quote About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
Angercraft Posted May 2, 2019 Posted May 2, 2019 19 hours ago, Cadiboo said: If you want them in your developer environment put them in ./libs or use maven. If you want them packaged with your mod in a production environment use forges jar-in-jar system How do you do this? I tried reading the guide at https://mcforge.readthedocs.io/en/latest/gettingstarted/dependencymanagement/ but I can't really figure it out. It says we have to drop the jar into our own jar, but where should we place it? The ContainedDeps manifest attribute should hold a list of our .jar dependencies, but should we manually add this to our builded mods manifest, inside the mod jar, or how do we handle this? Thank you in advance! Quote
Cadiboo Posted May 4, 2019 Posted May 4, 2019 Take a look at https://www.minecraftforge.net/forum/topic/69816-classes-not-found-during-runtime/ and https://www.minecraftforge.net/forum/topic/69515-how-to-add-another-mod-to-his-workspace-on-eclipse-a-mod-dependency/?do=findComment&comment=336200 Quote About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
Recommended Posts
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.