Jump to content

Using Apache Commons Math in my mod


Asweez

Recommended Posts

I want to use the math library from apache commons. However, just including it in the build path doesn't include it in the build. I don't want to just use the sources in my mod because that could create compatibility issues (I'm assuming some other mods use commons math). How do I include it in my build?

Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod.

Link to comment
Share on other sites

Same way as how I told you in your previous thread about shading. Use the Shadow plugin, tell it to include you're version of Commons Math and tell it to relocate it to a package inside your mod package.

 

You can see an example of this here.

Don't make mods if you don't know Java.

Check out my website: http://shadowfacts.net

Developer of many mods

Link to comment
Share on other sites

So would I just use

relocate "org.apache.commons.math3", "my package here"

?

 

If so, where do I put the org.apache.commons.math3, and when I relocate it into my package in my mod, how do I make my mod files reference Commons Math when it hasn't been relocated to that package yet (in the dev environment)?

 

Thanks

Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod.

Link to comment
Share on other sites

Yes, what i usually do is:

 

relocate "org.apache.commons.math3", "your.mod.package.repack.org.apache.commons.math3"

 

The whole point of having the

relocate

function is that it both moves the files and updates all the references in your code and in the other library.

Don't make mods if you don't know Java.

Check out my website: http://shadowfacts.net

Developer of many mods

Link to comment
Share on other sites

Thanks!

 

I still get a NoClassDefFoundError for org.gradle.api.plugins.JavaPlugin, is there something else I need to do?

 

build.gradle

 

buildscript {
    repositories {
        jcenter()
        maven {
            name = "forge"
            url = "http://files.minecraftforge.net/maven"
        }
    }
    dependencies {
            classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT'
    }
}

plugins{
    id "com.github.johnrengelman.shadow" version "1.2.2"
}

apply plugin: "net.minecraftforge.gradle.forge"

version = "1.0"
group= "com.apmods.hpspells" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "hpspells"

minecraft {
    version = "1.7.10-10.13.4.1614-1.7.10"
    runDir = "eclipse"
}

processResources
{
    inputs.property "version", project.version
    inputs.property "mcversion", project.minecraft.version

    from(sourceSets.main.resources.srcDirs) {
        include 'mcmod.info'
                
        expand 'version':project.version, 'mcversion':project.minecraft.version
    }
        
    from(sourceSets.main.resources.srcDirs) {
        exclude 'mcmod.info'
    }
}

shadowJar{
    relocate "org.apache.commons.math3", "com.apmods.hpspells.repack.org.apache.commons.math3"
}


 

Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod.

Link to comment
Share on other sites

Ok, I updated gradle to version 2.12 and that is working, however when I run

gradlew build

it comes up with this error.

 

> Failed to apply plugin [class 'com.github.jengelman.gradle.plugins.shadow.ShadowJavaPlugin']
   > Could not create task of type 'ShadowJar'.

 

 

Here is my build.grade, what am I doing wrong?

 

buildscript {
    repositories {
        jcenter()
        maven {
            name = "forge"
            url = "http://files.minecraftforge.net/maven"
        }
        maven {
            name = "sonatype"
            url = "https://oss.sonatype.org/content/repositories/snapshots/"
        }
    }
    dependencies {
        classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT'
    }
}

plugins{
id "com.github.johnrengelman.shadow" version "1.2.2"
}

apply plugin: 'java'
apply plugin: "com.github.jengelman.gradle.plugins.shadow"
apply plugin: 'forge'

version = "1.0"
group= "com.apmods.hpspells" 
archivesBaseName = "hpspells"

minecraft {
    version = "1.7.10-10.13.4.1558-1.7.10"
    runDir = "eclipse"
}

dependencies {
    // you may put jars on which you depend on in ./libs
    // or you may define them like so..
    //compile "some.group:artifact:version:classifier"
    //compile "some.group:artifact:version"
      
    // real examples
    //compile 'com.mod-buildcraft:buildcraft:6.0.8:dev'  // adds buildcraft to the dev env
    //compile 'com.googlecode.efficient-java-matrix-library:ejml:0.24' // adds ejml to the dev env

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

}

processResources
{
    // this will ensure that this task is redone when the versions change.
    inputs.property "version", project.version
    inputs.property "mcversion", project.minecraft.version

    // replace stuff in mcmod.info, nothing else
    from(sourceSets.main.resources.srcDirs) {
        include 'mcmod.info'
                
        // replace version and mcversion
        expand 'version':project.version, 'mcversion':project.minecraft.version
    }
        
    // copy everything else, thats not the mcmod.info
    from(sourceSets.main.resources.srcDirs) {
        exclude 'mcmod.info'
    }
}

shadowJar{
    relocate "org.apache.commons.math3", "com.apmods.hpspells.repack.org.apache.commons.math3"
}

 

Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod.

Link to comment
Share on other sites

Ah, silly mistake, it was a bug in version 1.2.2 of shadowJar, I updated to 1.2.3 and it was fixed.

 

However, now when I run it it throws several errors because it can't find any of the apache commons math classes. My build.gradle is posted above. I have added apache commons math3 as an external jar to Minecraft's build path. Any help would be appreciated.

 

Thanks

Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod.

Link to comment
Share on other sites

Thanks! That worked. Here is my build.grade for anyone wondering.

 

buildscript {
    repositories {
        jcenter()
        maven {
            name = "forge"
            url = "http://files.minecraftforge.net/maven"
        }
        maven {
            name = "sonatype"
            url = "https://oss.sonatype.org/content/repositories/snapshots/"
        }
    }
    dependencies {
        classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT'
    }
}

plugins{
id "com.github.johnrengelman.shadow" version "1.2.3"
}

apply plugin: 'java'
apply plugin: 'forge'

version = "1.0"
group= "com.apmods.hpspells" 
archivesBaseName = "hpspells"

minecraft {
    version = "1.7.10-10.13.4.1558-1.7.10"
    runDir = "eclipse"
}

dependencies {
    compile group: "org.apache.commons", name: "commons-math3", version: "3.2"
}

processResources
{
    inputs.property "version", project.version
    inputs.property "mcversion", project.minecraft.version

    from(sourceSets.main.resources.srcDirs) {
        include 'mcmod.info'
                
        expand 'version':project.version, 'mcversion':project.minecraft.version
    }
        
    from(sourceSets.main.resources.srcDirs) {
        exclude 'mcmod.info'
    }
}

shadowJar{
    relocate "org.apache.commons.math3", "com.apmods.hpspells.repack.org.apache.commons.math3"
}

Creator of the MyFit, MagiCraft, Tesseract gun, and Papa's Wingeria mod.

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

    • Is there a way to copy effect for example Darkness or Nausea? Like an absolute copy
    • Tapi sebelum itu kalian sudah tahu belum kenapa kami menyarankan DUTA89 kepada kalian semua? Karena DUTA89 bisa dikatakan sebagai salah satu tempat atau wadah untuk menghasilkan uang dengan cepat dan mudah hanya dengan modal receh dan rebahan saja
    • It is painful to invest and lose, binary options are more of a gamble if you ask me, especially when your broker decides to invest on your behalf. That's how I lost all my funds thanks to my broker who claimed to have invested on my behalf and lost a sum of 115,000 USD. This made me realize that people should really be careful out there especially when funds are involved, this is not to say recovery is not possible even though there are several frauds out there who claim they can recover your funds. This will only depend if you have done your research on the recovery agent that you would want to use to help you. After what happened to me, I wouldn’t like the same situation to happen to me, losing money. I did a thorough check on CYBERSPACE HACK PRO after coming across numerous testimonies on him helping lots of people to recover their funds/BTC. It took me a whole week to decide if I would be doing the right thing by hiring him. I emailed on Cyberspacehackpro(@)rescueteam.com and he responded. Asked him various questions and he really did impress me; he really knew his way on recovery. After providing all the necessary details, he did his incredible work and in 4 days time, my funds were recovered. Whether someone outside there feels like whatever I did to recover my funds rather than report it to the police was through unethical means, I wouldn’t care because as far as I am concerned, I don’t care because I was able to retrieve my hard-earned funds taken from me and that’s all, a big thank you to CYBERSPACE HACK PRO Recovery. CONTACT: CYBERSPACE HACK PRO Email: Cyberspacehackpro(@)rescueteam.com
    • Im using exaroton hosting with mods. Im play normally with my friends, and in some point the server freezes, and eventually kicks us for ''time out'', and the server never unfreezes again. when i reload the server, the world doesn't suffer any damage, but the players seem to go back in time. Example: I'm in a cave mining diamonds and I collect them. The server freezes and times out. when I restart the server, the cave diamonds are gone, but they are not in my inventory either. as if the player has gone back in time, but the world has not. Its really annoying for me and my friends. If someone can help me ill be so grateful. It doesn't seem to be any error in the console nor log.
    • Logs: https://pastebin.com/LBZs2U25
  • Topics

×
×
  • Create New...

Important Information

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