Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • Adding org.apache Libraries To Mod
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 2
Jack Richard

Adding org.apache Libraries To Mod

By Jack Richard, September 27, 2020 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

Jack Richard    0

Jack Richard

Jack Richard    0

  • Tree Puncher
  • Jack Richard
  • Members
  • 0
  • 30 posts
Posted September 27, 2020

I'm using version 1.15.2, and I'm trying to include Apache Commons Exec in my mod. 

From what I've read, you can't use it like a normal dependency. But, the Apache library is a prerequisite for the dependency I am adding, so I don't think I can simply relocate it.

How can I use this?

 

Thanks in advance.

  • Quote

Share this post


Link to post
Share on other sites

ChampionAsh5357    165

ChampionAsh5357

ChampionAsh5357    165

  • World Shaper
  • ChampionAsh5357
  • Members
  • 165
  • 1038 posts
Posted September 27, 2020
27 minutes ago, Jack Richard said:

so I don't think I can simply relocate it.

Well technically, that's what you have to do by shadowing the jar into your own using Gradle. This allows others to use your mod without requiring some dependency that might or might not already be on their system.

  • Quote

Share this post


Link to post
Share on other sites

Jack Richard    0

Jack Richard

Jack Richard    0

  • Tree Puncher
  • Jack Richard
  • Members
  • 0
  • 30 posts
Posted September 27, 2020
27 minutes ago, ChampionAsh5357 said:

Well technically, that's what you have to do by shadowing the jar into your own using Gradle.

I looked into shadowing, and I added the plugin to my Gradle file. Before, I was "shading" using this:

configurations.shade.each { dep ->
        from(project.zipTree(dep)){
            exclude 'META-INF', 'META-INF/**'
        }
    }

...but I'm guessing that isn't the same thing.

 

I needed to use version 4.0.4, because 6.0 didn't support the version of Gradle I'm using.

When I build the jar, the logs show a NoClassDefFoundError for the main package of the dependency.

 

All I've added to build.gradle is:

buildscript {
    repositories {
        maven { url = 'https://files.minecraftforge.net/maven' }
        maven { url = "https://plugins.gradle.org/m2/" }
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true
        classpath "com.github.jengelman.gradle.plugins:shadow:4.0.4"
    }
}
apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'eclipse'
apply plugin: 'maven-publish'
apply plugin: "com.github.johnrengelman.shadow"
dependencies {
    minecraft 'net.minecraftforge:forge:1.15.2-31.2.36'

    shadow 'nameofdependency'
}

 

Maybe there is more configuration needed?

  • Quote

Share this post


Link to post
Share on other sites

ChampionAsh5357    165

ChampionAsh5357

ChampionAsh5357    165

  • World Shaper
  • ChampionAsh5357
  • Members
  • 165
  • 1038 posts
Posted September 27, 2020

You shouldn't need to edit the buildscript at all. Plugins are applied using the plugins{} block although what you are doing will work as well. I believe the keyword to use is shade instead of shadow with shade being a configuration. You would also need a shadowJar{} block to specify where to relocate the files to.

  • Quote

Share this post


Link to post
Share on other sites

Jack Richard    0

Jack Richard

Jack Richard    0

  • Tree Puncher
  • Jack Richard
  • Members
  • 0
  • 30 posts
Posted September 27, 2020
17 minutes ago, ChampionAsh5357 said:

You shouldn't need to edit the buildscript at all. Plugins are applied using the plugins{} block although what you are doing will work as well.

I changed it to use the plugins{} block instead.

17 minutes ago, ChampionAsh5357 said:

I believe the keyword to use is shade instead of shadow with shade being a configuration.

shade wasn't a valid option, so I stuck with shadow. But I see some examples just using compile, does that work anyway?

19 minutes ago, ChampionAsh5357 said:

You would also need a shadowJar{} block to specify where to relocate the files to.

Okay, here's my shadowJar{} block I added:

shadowJar {
    relocate 'org.apache', 'org.(modid).apache'
}

 

I'm still getting NoClassDefFoundError, though.

 

Thanks for your help so far.

  • Quote

Share this post


Link to post
Share on other sites

Jack Richard    0

Jack Richard

Jack Richard    0

  • Tree Puncher
  • Jack Richard
  • Members
  • 0
  • 30 posts
Posted September 27, 2020

I'm trying to use this guide now. Forge doesn't seem to have srgExtra or extraLines anymore, is there an alternative?

  • Quote

Share this post


Link to post
Share on other sites

DaemonUmbra    541

DaemonUmbra

DaemonUmbra    541

  • Reality Controller
  • DaemonUmbra
  • Forum Team
  • 541
  • 10340 posts
Posted September 28, 2020

That guide is ANCIENT, throw it away.

I don't think that bit is needed now

  • Quote

This is my Forum Signature, I am currently attempting to transform it into a small guide for fixing easier issues using spoiler blocks to keep things tidy.

 

As the most common issue I feel I should put this outside the main bulk:

The only official source for Forge is https://files.minecraftforge.net, and the only site I trust for getting mods is CurseForge.

If you use any site other than these, please take a look at the StopModReposts project and install their browser extension, I would also advise running a virus scan.

 

For players asking for assistance with Forge please expand the spoiler below and read the appropriate section(s) in its/their entirety.

Spoiler

Logs (Most issues require logs to diagnose):

Spoiler

Please post logs using one of the following sites (Thank you Lumber Wizard for the list):

https://gist.github.com/: 100MB Requires member (Free)

https://pastebin.com/: 512KB as guest, 10MB as Pro ($$$)

https://hastebin.com/: 400KB

Do NOT use sites like Mediafire, Dropbox, OneDrive, Google Drive, or a site that has a countdown before offering downloads.

 

What to provide:

...for Crashes and Runtime issues:

Minecraft 1.14.4 and newer:

Post debug.log

Older versions:

Please update...

 

...for Installer Issues:

Post your installer log, found in the same place you ran the installer

This log will be called either installer.log or named the same as the installer but with .log on the end

Note for Windows users:

Windows hides file extensions by default so the installer may appear without the .jar extension then when the .log is added the log will appear with the .jar extension

 

Where to get it:

Mojang Launcher: When using the Mojang launcher debug.log is found in .minecraft\logs.

 

Twitch Launcher: If you are using the Twitch Launcher, their configurations break Forge's log settings, fortunately there is an easier workaround than I originally thought, this works even with Twitch's installation of the Minecraft launcher as long as it is not launched THROUGH Twitch:

Spoiler
  1. Make sure you have the correct version of Forge installed (some packs are heavily dependent on one specific build of Forge)
  2. Make a launcher profile targeting this version of Forge.
  3. Set the launcher profile's GameDir property to the pack's instance folder (not the instances folder, the folder that has the pack's name on it).
  4. Now launch the pack through that profile and follow the "Mojang Launcher" instructions above.

Video:

Spoiler

 

 

 

or alternately, 

 

Fallback ("No logs are generated"):

If you don't see logs generated in the usual place, provide the launcher_log.txt from .minecraft

 

Server Not Starting:

Spoiler

If your server does not start or a command window appears and immediately goes away, run the jar manually and provide the output.

 

Reporting Illegal/Inappropriate Adfocus Ads:

Spoiler

Get a screenshot of the URL bar or copy/paste the whole URL into a thread on the General Discussion board with a description of the Ad.

Lex will need the Ad ID contained in that URL to report it to Adfocus' support team.

 

Posting your mod as a GitHub Repo:

Spoiler

When you have an issue with your mod the most helpful thing you can do when asking for help is to provide your code to those helping you. The most convenient way to do this is via GitHub or another source control hub.

When setting up a GitHub Repo it might seem easy to just upload everything, however this method has the potential for mistakes that could lead to trouble later on, it is recommended to use a Git client or to get comfortable with the Git command line. The following instructions will use the Git Command Line and as such they assume you already have it installed and that you have created a repository.

 

  1. Open a command prompt (CMD, Powershell, Terminal, etc).
  2. Navigate to the folder you extracted Forge’s MDK to (the one that had all the licenses in).
  3. Run the following commands:
    1. git init
    2. git remote add origin [Your Repository's URL]
      • In the case of GitHub it should look like: https://GitHub.com/[Your Username]/[Repo Name].git
    3. git fetch
    4. git checkout --track origin/master
    5. git stage *
    6. git commit -m "[Your commit message]"
    7. git push
  4. Navigate to GitHub and you should now see most of the files.
    • note that it is intentional that some are not synced with GitHub and this is done with the (hidden) .gitignore file that Forge’s MDK has provided (hence the strictness on which folder git init is run from)
  5. Now you can share your GitHub link with those who you are asking for help.

[Workaround line, please ignore]

 

Share this post


Link to post
Share on other sites

Jack Richard    0

Jack Richard

Jack Richard    0

  • Tree Puncher
  • Jack Richard
  • Members
  • 0
  • 30 posts
Posted September 28, 2020
26 minutes ago, DaemonUmbra said:

That guide is ANCIENT, throw it away.

I don't think that bit is needed now

I'm guessing I still need to move the Apache library somehow, because I always get NoClassDefFoundError when calling it... If you still aren't allowed to use Apache libraries (I read old forum posts saying you can't include those normally), I guess that would explain the error. 

I couldn't figure out the Shadow plugin, it didn't seem to include any dependencies, so I used that guide, I'll try again with Shadow.

 

Thanks.

  • Quote

Share this post


Link to post
Share on other sites

Jack Richard    0

Jack Richard

Jack Richard    0

  • Tree Puncher
  • Jack Richard
  • Members
  • 0
  • 30 posts
Posted September 28, 2020

At this point, I've reimplemented the Shadow plugin, but it makes no changes to the jar unless I use:

project.tasks.build.dependsOn shadowJar

which makes a much larger jar, and I assume my dependencies are somewhere in there, but Minecraft does not recognize it as a mod. 

When I used the dependencies{} block in the shadowJar{} block, and included my dependencies, it would generate a 1 KB jar, which is definitely not right at all.

 

Other than including the plugin, here's the code that Shadow effects:

dependencies {
    minecraft 'net.minecraftforge:forge:1.15.2-31.2.36'

    compile group: 'org.seleniumhq.selenium', name:'selenium-java', version:'3.141.59'
}

shadowJar {
    relocate 'org.apache.commons.exec', 'org.(modid).apache.commons.exec'
    classifier ''
}

 

Thanks all for your help.

  • Quote

Share this post


Link to post
Share on other sites

Jack Richard    0

Jack Richard

Jack Richard    0

  • Tree Puncher
  • Jack Richard
  • Members
  • 0
  • 30 posts
Posted September 28, 2020

All my libraries are inside the jar now, but Minecraft does not recognize it as a mod anymore...

  • Quote

Share this post


Link to post
Share on other sites

ChampionAsh5357    165

ChampionAsh5357

ChampionAsh5357    165

  • World Shaper
  • ChampionAsh5357
  • Members
  • 165
  • 1038 posts
Posted September 28, 2020

In the development environment or the finalized jar?

  • Quote

Share this post


Link to post
Share on other sites

Jack Richard    0

Jack Richard

Jack Richard    0

  • Tree Puncher
  • Jack Richard
  • Members
  • 0
  • 30 posts
Posted September 28, 2020
3 minutes ago, ChampionAsh5357 said:

In the development environment or the finalized jar?

It runs fine with runClient, but when it's built, it's not recognized at all.

  • Quote

Share this post


Link to post
Share on other sites

ChampionAsh5357    165

ChampionAsh5357

ChampionAsh5357    165

  • World Shaper
  • ChampionAsh5357
  • Members
  • 165
  • 1038 posts
Posted September 28, 2020
14 minutes ago, Jack Richard said:

but when it's built, it's not recognized at all.

Hmmm, my only guess is that it's iterating through the apache commons package directory and skipping yours. As for how to fix this, you might have to do something more with relocate, but that is the best I can think of.

  • Quote

Share this post


Link to post
Share on other sites

Jack Richard    0

Jack Richard

Jack Richard    0

  • Tree Puncher
  • Jack Richard
  • Members
  • 0
  • 30 posts
Posted September 28, 2020
56 minutes ago, ChampionAsh5357 said:

Hmmm, my only guess is that it's iterating through the apache commons package directory and skipping yours. As for how to fix this, you might have to do something more with relocate, but that is the best I can think of.

 

I've relocated the Apache libraries now, but it's still not recognizing. When I recompile the jar, it appears that it has additionally copied all of Minecraft Forge's files. I think Shadow is picking up the:

minecraft 'net.minecraftforge:forge:1.15.2-31.2.36'

in dependencies{}...

 

I can't get exclude to work on this dependency, and I think this may be the solution.

  • Quote

Share this post


Link to post
Share on other sites

ChampionAsh5357    165

ChampionAsh5357

ChampionAsh5357    165

  • World Shaper
  • ChampionAsh5357
  • Members
  • 165
  • 1038 posts
Posted September 28, 2020
6 minutes ago, Jack Richard said:

 

I can't get exclude to work on this dependency, and I think this may be the solution.

I believe you would need to set the configurations to only include whichever you need using configurations = [project_configs]. That's why I said create a configuration called shade before so that you could call that.

  • Quote

Share this post


Link to post
Share on other sites

Jack Richard    0

Jack Richard

Jack Richard    0

  • Tree Puncher
  • Jack Richard
  • Members
  • 0
  • 30 posts
Posted September 28, 2020
1 minute ago, ChampionAsh5357 said:

I believe you would need to set the configurations to only include whichever you need using configurations = [project_configs]. That's why I said create a configuration called shade before so that you could call that.

Now we're getting somewhere... here's my build.gradle:

configurations {
    provided
    compile.extendsFrom provided
}

dependencies {
    minecraft 'net.minecraftforge:forge:1.15.2-31.2.36'

    shadow group: 'org.seleniumhq.selenium', name:'selenium-java', version:'3.141.59'
}

shadowJar {
    configurations = [project.configurations.shadow]

    classifier ''

    relocate('org.apache', 'org.(modid).apache')
}

processResources {
    inputs.property "version", project.version
    inputs.property "mcversion", "1.15.2-31.2.36"

    from(sourceSets.main.resources.srcDirs) {
        include 'mcmod.info'
        expand 'version':project.version, 'mcversion': "1.15.2-31.2.36"
    }

    from(sourceSets.main.resources.srcDirs) {
        exclude 'mcmod.info'
    }
}

project.tasks.build.dependsOn shadowJar

 

The file size drastically shrinks, and Minecraft recognizes it as a mod! 

But now, I'm getting:

java.lang.NoClassDefFoundError: org/(modid)/apache/logging/log4j/LogManager

So there might be more work to do...

  • Quote

Share this post


Link to post
Share on other sites

ChampionAsh5357    165

ChampionAsh5357

ChampionAsh5357    165

  • World Shaper
  • ChampionAsh5357
  • Members
  • 165
  • 1038 posts
Posted September 28, 2020

You seem to have copied the apache libraries that are already present in forge as well.

  • Quote

Share this post


Link to post
Share on other sites

Jack Richard    0

Jack Richard

Jack Richard    0

  • Tree Puncher
  • Jack Richard
  • Members
  • 0
  • 30 posts
Posted September 28, 2020
30 minutes ago, ChampionAsh5357 said:

You seem to have copied the apache libraries that are already present in forge as well.

I used this to get the libraries back:

shadow group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.11.2'
shadow group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.11.2'

But now I'm getting this:

java.lang.NoSuchMethodError: com.google.common.util.concurrent.SimpleTimeLimiter.create(Ljava/util/concurrent/ExecutorService;)Lcom/google/common/util/concurrent/SimpleTimeLimiter;

 

  • Quote

Share this post


Link to post
Share on other sites

Jack Richard    0

Jack Richard

Jack Richard    0

  • Tree Puncher
  • Jack Richard
  • Members
  • 0
  • 30 posts
Posted September 28, 2020

I changed my shadowJar config to this:

shadowJar {
    relocate('com.google', 'org.(modid).google')
    configurations = [project.configurations.shadow]

    classifier ''

    relocate('org.apache', 'org.(modid).apache')
}

And I have success!

  • Quote

Share this post


Link to post
Share on other sites

Jack Richard    0

Jack Richard

Jack Richard    0

  • Tree Puncher
  • Jack Richard
  • Members
  • 0
  • 30 posts
Posted September 28, 2020
16 minutes ago, Jack Richard said:

I changed my shadowJar config to this:


shadowJar {
    relocate('com.google', 'org.(modid).google')
    configurations = [project.configurations.shadow]

    classifier ''

    relocate('org.apache', 'org.(modid).apache')
}

And I have success!

But now that I've entered the game, I've noticed a fatal flaw. None of my block or items registered. I think it's because of ignoring the Minecraft dependencies, so I'll need to keep on working.

  • Quote

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 2
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • cadbane86140
      Minecraft: Hunger Games Game #36- Shear FIGHT!

      By cadbane86140 · Posted 1 hour ago

      Hello There! Today we are back on Hunger Games after a little break but we are finally back! In this episode we are on the good ol' map Survival Games 4 and it ACTUALLY went well for once. Also we have so many great battles on rooftops, small rooms and just out in the open! We also use shears to fight at one point and that was pretty crazy! There are so many hilarious moments in this episode that I know you guys are gonna love! I hope you all enjoy this video and if you did don't forget to like and sub for more Hunger Games in the future!  
    • Sad Whale
      Game crashes whenever I try to increase the RAM

      By Sad Whale · Posted 1 hour ago

      latest.log
    • diesieben07
      Game crashes whenever I try to increase the RAM

      By diesieben07 · Posted 1 hour ago

      In the logs folder of your game directory.
    • Unusualty
      GUI'S and player editing

      By Unusualty · Posted 1 hour ago

      So I'm trying to make a mod that is inspired by Origin's because this mod isn't for forge I was wondering if anyone can help me do something like this where you get a GUI when you join the world where you can select a race that has abilities and down sides to them, I also want to have classes but first I want these race's done so if anyone can help this would be appreciated.
    • Sad Whale
      Game crashes whenever I try to increase the RAM

      By Sad Whale · Posted 1 hour ago

      Would you mind explaining where I can find the debug.log
  • Topics

    • cadbane86140
      0
      Minecraft: Hunger Games Game #36- Shear FIGHT!

      By cadbane86140
      Started 1 hour ago

    • Sad Whale
      6
      Game crashes whenever I try to increase the RAM

      By Sad Whale
      Started 2 hours ago

    • Unusualty
      0
      GUI'S and player editing

      By Unusualty
      Started 1 hour ago

    • fluiX
      1
      server wont start

      By fluiX
      Started 2 hours ago

    • Luis_ST
      6
      [1.16.5] Help with custom Event

      By Luis_ST
      Started 7 hours ago

  • Who's Online (See full list)

    • Beethoven92
    • NullDev
    • diesieben07
    • Kawaiialexplays
    • matezz
    • CookieLukas
    • LexManos
    • anteos
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • Adding org.apache Libraries To Mod
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community