Isador
Isador

Reputation: 41

Minecraft [GRADLE] 1.7.2 - Cannot use external .jar?

I'm using the apache library httpcomponents in my mod. So I have 7 jar files, that I've added in my buildpath on Eclipse.

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

But when I use gradle build command, the custom buildpath isn't considered.

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

Code:

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 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 tried to use the code:

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 :/

isador34

Upvotes: 1

Views: 1340

Answers (3)

metadaddy
metadaddy

Reputation: 4419

Add the following to the end of build.gradle to include your dependencies in the compilation:

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

To build a 'fat jar' containing the classes for all your dependencies, instead 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) } }
}

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

Upvotes: 0

kuporific
kuporific

Reputation: 10322

I'm assuming you're working off of the ForgeGradle github repo. If so, I'm also assuming you're modifying their build.gradle file. You might try declaring your dependencies in a similar way. For example, instead of

 compile files('lib/httpcomponents-client/httpcore-4.3.2.jar')

try

compile 'org.apache.httpcomponents:httpcomponents-core:4.3.2'

Gradle should pick these up from Maven Central (since the repositories { } block declares mavenCentral() at the end).

You can track down each of your dependencies by searching for it on Maven Central.

Upvotes: 0

Peter Niederwieser
Peter Niederwieser

Reputation: 123920

You added the dependencies in the wrong place. They need to go into dependencies { ... }, not into buildscript { dependencies { ... } }. The former is used for declaring dependencies of your code, the latter for declaring dependencies of the build itself (e.g. Gradle plugins).

PS: It would be easier to resolve these dependencies from Maven Central.

Upvotes: 2

Related Questions