Jump to content

Recommended Posts

Posted

Hi :)

I'm using the apache library httpcomponents in my mod.

So I've 7 jar files, I've added in my buildpath on Eclipse.

 

Then compile with eclipse works. When I launch my mod with eclipse it's work.

 

But when I use gradle build command, the custom buildpath is'nt considered.

 

I see I must modify the build.gradle file. I've try ...

 

dependencies {
        classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT'
        compile files('lib/httpcomponents-client/commons-codec-1.6.jar')
        compile files('lib/httpcomponents-client/commons-logging-1.1.3.jar')
        compile files('lib/httpcomponents-client/fluent-hc-4.3.3.jar')
        compile files('lib/httpcomponents-client/httpclient-4.3.3.jar')
        compile files('lib/httpcomponents-client/httpclient-cache-4.3.3.jar')
        compile files('lib/httpcomponents-client/httpcore-4.3.2.jar')
        compile files('lib/httpcomponents-client/httpmime-4.3.3.jar')
       
    }

 

but it's doesn't work, "Could not find method compile() for arguments [file collection] on org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler_Decorated@76454e71."

 

And I've try to use

dependencies {
        classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT'
        runtime fileTree(dir: 'lib/httpcomponents-client', include: '*.jar')
    }

 

but I've an error too, "Could not find method runtime() for arguments [directory 'lib/httpcomponents-client'] on org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler_Decorated@40211960."

 

Could you help me please ?

Thanks, and sorry for my bad english :/

 

Blackout

Posted

Thanks a lot, building with gradle works now :D

But I have an other problem, when I launch my game, it's crash because classLoader don't find externals librairies required by my mod.

What can I do to solve it please ? Thanks :)

 

Posted

Hi,

 

I did it, but I still have this error  :'(

 

This is the error report :

[19:39:56 INFO]: Client> [19:39:56] [Client thread/INFO] [FML]: FML has found a non-mod file commons-codec-1.6.jar in your mods directory. It will now be injected into your classpath. This could severe stability issues, it should be removed if possible.
[19:39:56 INFO]: Client> [19:39:56] [Client thread/INFO] [FML]: FML has found a non-mod file commons-logging-1.1.3.jar in your mods directory. It will now be injected into your classpath. This could severe stability issues, it should be removed if possible.
[19:39:56 INFO]: Client> [19:39:56] [Client thread/INFO] [FML]: FML has found a non-mod file fluent-hc-4.3.3.jar in your mods directory. It will now be injected into your classpath. This could severe stability issues, it should be removed if possible.
[19:39:56 INFO]: Client> [19:39:56] [Client thread/INFO] [FML]: FML has found a non-mod file httpclient-4.3.3.jar in your mods directory. It will now be injected into your classpath. This could severe stability issues, it should be removed if possible.
[19:39:56 INFO]: Client> [19:39:56] [Client thread/INFO] [FML]: FML has found a non-mod file httpclient-cache-4.3.3.jar in your mods directory. It will now be injected into your classpath. This could severe stability issues, it should be removed if possible.
[19:39:56 INFO]: Client> [19:39:56] [Client thread/INFO] [FML]: FML has found a non-mod file httpcore-4.3.2.jar in your mods directory. It will now be injected into your classpath. This could severe stability issues, it should be removed if possible.
[19:39:56 INFO]: Client> [19:39:56] [Client thread/INFO] [FML]: FML has found a non-mod file httpmime-4.3.3.jar in your mods directory. It will now be injected into your classpath. This could severe stability issues, it should be removed if possible.
[19:39:58 INFO]: Client> [19:39:58] [Client thread/INFO] [FML]: Configured a dormant chunk cache size of 0
[19:39:58 INFO]: Client> 
[19:39:58 INFO]: Client> Starting up SoundSystem...
[19:39:58 INFO]: Client> Initializing LWJGL OpenAL
[19:39:58 INFO]: Client>     (The LWJGL binding of OpenAL.  For more information, see http://www.lwjgl.org)
[19:40:01 INFO]: Client> OpenAL initialized.
[19:40:01 INFO]: Client> 
[19:40:02 INFO]: Client> [19:40:01] [sound Library Loader/INFO]: Sound engine started
[19:40:05 INFO]: Client> [19:40:05] [Client thread/INFO]: Created: 512x256 textures/blocks-atlas
[19:40:05 INFO]: Client> [19:40:05] [Client thread/INFO]: Created: 256x256 textures/items-atlas
[19:40:06 INFO]: Client> [19:40:06] [Client thread/ERROR] [FML]: Fatal errors were detected during the transition from INITIALIZATION to POSTINITIALIZATION. Loading cannot continue
[19:40:06 INFO]: Client> [19:40:06] [Client thread/ERROR] [FML]: 
[19:40:06 INFO]: Client> 	mcp{9.03} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized
[19:40:06 INFO]: Client> 	FML{7.2.165.1065} [Forge Mod Loader] (forge-1.7.2-10.12.1.1065.jar) Unloaded->Constructed->Pre-initialized->Initialized
[19:40:06 INFO]: Client> 	Forge{10.12.1.1065} [Minecraft Forge] (forge-1.7.2-10.12.1.1065.jar) Unloaded->Constructed->Pre-initialized->Initialized
[19:40:06 INFO]: Client> 	externalJarExample{1.0} [External Jar] (externalJarExemple-1.0.jar) Unloaded->Constructed->Pre-initialized->Errored
[19:40:06 INFO]: Client> [19:40:06] [Client thread/ERROR] [FML]: The following problems were captured during this phase
[19:40:06 INFO]: Client> [19:40:06] [Client thread/ERROR] [FML]: Caught exception from externalJarExample
[19:40:06 INFO]: Client> java.lang.NoClassDefFoundError: org/apache/http/HttpEntity

 

Do you have any idea ? Thanks :)

Posted

I have exactly the same problem. Forge loads whatever you put in the mods directory, but the actual mod can't 'see' its dependencies. Perhaps they are all loaded into different class loaders.

 

In 1.6.4, I wrote a script to extract all the class files from the dependent libraries into the same directory as the mod itself, and jar the whole lot up together. I'm trying to figure out how to do the same in Gradle rather an a shell script. If I figure it out, I'll post it back here.

Posted

I have my idea to solve the problem.

In fact gradle uses dependencies to build the .jar but don't include referencies to external jar.

So it's like you don't know the jar after the compilation.

I think when the external jar is in your classpath (so put into your mods folder), you should do a Class.forname(), It should be works. I don't try, but will try it this week (If I have time, I hope :P).

Posted

OK - the good news - I figured out the Gradle magic to include dependent JARs in your mod JAR. At the end of build.gradle, add:

 

configurations {
    external
    compile.extendsFrom external
}

dependencies {
    external 'org.apache.httpcomponents:httpclient:4.3.3'
    external 'org.apache.httpcomponents:httpcore:4.3.2'
    // etc
}

jar {
    from { configurations.external.collect { it.isDirectory() ? it : zipTree(it) } }
}

 

The bad news - mods using org.apache JARs will still not work, due to a bug in FML: https://github.com/MinecraftForge/FML/issues/424

Posted

YES! Got this all working, thanks to some input from LexManos and GUIpsp on my pull request.

 

The key is to use the Gradle Shadow plugin to relocate the external classes so they don't get excluded by FML, and there's no risk of clashing with different versions of the same JARs in other mods. Here's by build.gradle in its entirety, so you can see how it all works

 

buildscript {
    repositories {
        mavenCentral()
        maven {
            name = "forge"
            url = "http://files.minecraftforge.net/maven"
        }
        maven {
            name = "sonatype"
            url = "https://oss.sonatype.org/content/repositories/snapshots/"
        }
        jcenter()
    }
    dependencies {
        classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT'
        classpath 'eu.appsatori:gradle-fatjar-plugin:0.2-rc1'
        classpath 'com.github.jengelman.gradle.plugins:shadow:0.8'
    }
}

apply plugin: 'shadow'

shadow {
    classifier = 'mod' // My mod jar ends up as build/distributions/Forcecraft-1.7.2-0.2.0-mod.jar
    artifactSet {
        include 'us.forcecraft' // My mod's main package
    }
    relocation {
        pattern = 'argo'
        shadedPattern = 'us.forcecraft.argo'
    }
    relocation {
        pattern = 'org.apache'
        shadedPattern = 'us.forcecraft.org.apache'
    }
    relocation {
        pattern = 'org.cometd'
        shadedPattern = 'us.forcecraft.org.cometd'
    }
    relocation {
        pattern = 'org.eclipse'
        shadedPattern = 'us.forcecraft.org.eclipse'
    }
}

apply plugin: 'forge'

version = "1.7.2-0.2.0"
group= "us.forcecraft" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "Forcecraft"

minecraft {
    version = "1.7.2-10.12.1.1060"
    assetDir = "eclipse/assets"
}

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'
    }
}

// Include external libs in compilation and jar
configurations {
    external
    compile.extendsFrom external
}

dependencies {
    external 'net.sourceforge.argo:argo:2.25'
    external 'org.cometd.java:bayeux-api:2.2.0'
    external 'org.cometd.java:cometd-java-client:2.2.0'
    external 'org.cometd.java:cometd-java-common:2.2.0'
    external 'commons-logging:commons-logging:1.1.3'
    external 'commons-codec:commons-codec:1.6'
    external 'org.apache.httpcomponents:httpclient:4.3.3'
    external 'org.apache.httpcomponents:httpcore:4.3.2'
    external 'org.eclipse.jetty:jetty-client:7.4.0.v20110414'
    external 'org.eclipse.jetty:jetty-http:7.4.0.v20110414'
    external 'org.eclipse.jetty:jetty-io:7.4.0.v20110414'
    external 'org.eclipse.jetty:jetty-util:7.4.0.v20110414'
}

jar {
    from { configurations.external.collect { it.isDirectory() ? it : zipTree(it) } }
}

// Let Shadow do its thing
build.dependsOn shadowJar

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



×
×
  • Create New...

Important Information

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