Jump to content

[1.13.2] How to add external libs into a mod?


HenryFoster

Recommended Posts

 

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 by HenryFoster
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by HenryFoster
Link to comment
Share on other sites

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 by Angercraft
  • Like 1
Link to comment
Share on other sites

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

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.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)

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.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)

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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
  • Topics

×
×
  • Create New...

Important Information

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