Jump to content

[SOLVED] Link an API from Gradle


zumbrel

Recommended Posts

I've searched the forum about this important topic but I couldn't find anything suitable for me.

 

Using other mod's apis can be done in many ways:

1. Put the api code directly in your own project. This is, imo, the worst way to go. One should never include someone else's api in his own mod. (discussed here: http://www.minecraftforge.net/forum/index.php/topic,5303.msg30648.html#msg30648)

 

2. Put the api's jar in your project, reference it has a library and don't include it in your mod. That's what I'm using actually. (discussed here: http://www.minecraftforge.net/forum/index.php/topic,20546.msg104049.html#msg104049)

 

3. Notify gradle about the need for an external api and let it handle everything. That's what I want :)

 

The second option is nice but it has some drawbacks. I first have to find the apis. Some are easily obtainable as a jar, some are source code that have to be compiled first. They have to be manually copied into a libs folder and added as a dependency in gradle/eclipse. Handling the different versions and updates of the apis is a pain. The apis being in my libs folder, they are stored on my own repository where they shouldn't be.

 

Let's take Applied Energistics 2 as an example. On their github page they say:

When compiling against the AE2 API you can use gradle dependencies, just add

 

dependencies {
    compile "appeng:appliedenergistics2:rv_-_____-__:dev"
}

AE2 is available from the default forge maven so no additional repositories are necessary.

 

This is exactly what I need. I can set a variable holding the api's version I want in my build.properties and call the dependency in my gradle.build.

But when I do this, I get some issues that I don't understand.

First, after I run "gradle eclipse", my eclipse project is updated and immediately finds the api. It got downloaded with the previous command and got stored somewhere in ~/.gradle/caches. Eclipse is now happy and displays no error.

But then, when I run "gradle build" the build fails. I get spammed with messages like this:

> Could not resolve api:coloredlightscore:1.
  Required by:
      (mymod's name):1.7.10-1.2.0 > appeng:appliedenergistics2:rv2-beta-8
   > Could not HEAD 'https://libraries.minecraft.net/api/coloredlightscore/1/coloredlightscore-1.pom'. Received status code 403 from server: Forbidden

 

It puzzles me because it seems that gradle tries to compile the api! Which I don't understand for 2 reasons: the api is already compiled and actually already present in ~/.gradle/caches ; ae2's dependencies have nothing to do with my mod.

 

From researches on that matter, I've read that I have to include the sub-dependencies (like coloredlightscore in this example) in a gradle repository but that doesn't make any sense to me. I just can't add all the dependencies of all the apis I'm using. That has nothing to do with my own mod. And it would be such a pain that there would be no point using this method.

 

Another thing that puzzles me is the url given in the logs. Why looking for coloredlightscore (and all other dependencies) at libraries.minecraft.net? Doesn't make any sense to me :)

 

What did I do wrong and how can I solve this?

Link to comment
Share on other sites

Gradle isn't trying to "compile" the AE2 API. The AE2 API depends on ColoredLightsCore and therefore Gradle must also download it when download the AE2 API. This is not (shouldn't be) a problem with the way you've configured things, this is a problem with how the AE2 API is setup, you should ask the AE2 devs for help.

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

You got a point, gradle can't try to "compile" the api since the jar it gets is already made of compiled classes.

When I use the second option (the "compile file" command and a jar file of the api I manually put in my libs folder), gradle compiles fine and I cannot find any track of those api's dependencies in gradle/caches. So those dependencies are really not needed.

 

Let me sum up:

compile "appeng:appliedenergistics2:${ae2_version}:dev"

Gradle tries to get some useless dependencies and fails. Eclipse is happy tho.

 

compile files("libs/appliedenergistics2-${ae2_version}-dev.jar")

Gradle is happy.

 

Smells like a bug in gradle so I decided to upgrade it from 2.0 to 2.1 and tada! Now it works as expected :)

 

Thanks a lot for your insight mate!

Link to comment
Share on other sites

Arf, since I had to update gradle, I went up to gradle 2.3 and now nothing work :(

Previously, I was using gradle 2.0 for my project but I also had compile AE2 with their provided gradlew wrapper (which happened to be 2.1). Maybe that's why the dependencies got resolved when I moved to gradle 2.1 since all the dependencies jars have been already downloaded for AE2? I don't know.

I tried to recompile both AE2 and my project with gradle 2.3 and it still fails so I guess the problem is elsewhere. It seems that gradle handles the dependencies differently from maven so we need to explicitly tell gradle not to use all the dependencies found in maven's pom files.

 

dependencies {
    compile("appeng:appliedenergistics2:${ae2_version}:dev") {
        exclude group: 'api'
        exclude group: 'dev'
        exclude group: 'junit'
        exclude group: 'codechicken'
        exclude group: 'mcp.mobius.waila'
    }
}

This works. I got the group names in ae2 api's pom file. But even better, the next piece of code:

 

dependencies {
    compile("appeng:appliedenergistics2:${ae2_version}:dev") {
        transitive = false
    }
}

 

Works like a charm :) I'm just a bit worried because I first ran "gradle setupDecompWorkspace eclipse" which downloaded a few libs (like codechickenlib), then I turned off the transitive dependencies and ran "gradle build".

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



×
×
  • Create New...

Important Information

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