I can't use my own library with Gradle

I’m not sure if it is OK to ask this kind of question, but here is my problem.

I’m trying to make a library for Minecraft, especially for Paper.
It will provide some useful methods to plugin developers which requires NMS, without making them implement NMS in their dependencies. I don’t know what should I call this kind of library. Should I call it ‘wrapper’? anyway…

So I made it and put the codes on GitLab and used JitPack to make it able to be used for Minecraft plugin development.

The problem is, I can’t use it. Here is my build.gradle file’s content.

// Minecraft plugin for testing my library
plugins {
    id 'java'
}
group = 'test'
version = '1.0-SNAPSHOT'
repositories {
    mavenLocal()
    mavenCentral()
    maven { url = "https://jitpack.io" }
    maven { url = 'https://repo.papermc.io/repository/maven-public/' }
    maven { url = 'https://oss.sonatype.org/content/groups/public/' }
}
configurations.implementation.canBeResolved = true
configurations.compileOnly.canBeResolved = true
dependencies {
    compileOnly 'io.papermc.paper:paper-api:1.19.2-R0.1-SNAPSHOT'
    implementation "com.gitlab.exmserver:mol:main-SNAPSHOT" // This is my library
}

As you can see, I defined JitPack repository and implemented my library. Gradle should be able to pull it from JitPack, load it as dependency. It seems Gradle pulled my library from JitPack, but didn’t load it at all.

In my IDE(IntelliJ IDEA), I don’t see my library in ‘External Library’ section. Build from gradlew also failes while saying like ‘package com.gitlab.exmserver does not exist’ and ‘cannot find symbol’.

I’ve tried many things to solve this, like:

  • Press ‘Refresh’ button on Gradle panel of IDEA
  • Invalidate Cache (in IDEA)
  • Use Gradle instead of IDEA as build tool (this is default, though)
  • Delete Gradle caches directory and Maven repository directory
  • Force-kill all java.exe or Reboot my PC
  • Make JitPack to rebuild my library

If how my library is structured is important, here is the detail.
You can also see current code of my library from this link (same link above)

My library consist of two kind of module/subproject.

  • core: Provides interface for each bukkit_* module. Also provides some classes/methods that don’t require NMS.
  • bukkit_*: Provides actual implementation about interface of core for each Bukkit API version.

And here is brief tree of my library.

root
├ core
│    ├ src
│    └ build.gradle
├ bukkit_1_19_R1
│    ├ src
│    └ build.gradle
└ build.gradle

And here are the content of each build.gradle.

// build.gradle
plugins {
  id("java")
  id("maven-publish")
  id("com.github.johnrengelman.shadow") version("7.1.2")
}
dependencies {
  implementation(project(":bukkit_1_19_R1")) {
    exclude module: ":core"
  }
  implementation(project(":core"))
}
publishing {
  publications {
    shadow(MavenPublication) { publications ->
      project.shadow.component(publications)
    }
  }
}
allprojects {
  apply plugin: "java"

  repositories {
    mavenCentral()
    maven{ url = "https://repo.papermc.io/repository/maven-public/" }
  }

  group = "com.gitlab.exmserver"
  version = "1.0.0-SNAPSHOT"
}
// core/build.gradle
dependencies {
  compileOnly("io.papermc.paper:paper-api:1.19.2-R0.1-SNAPSHOT")
}
// bukkit_1_19_R1/build.gradle
plugins {
  id("io.papermc.paperweight.userdev") version("1.3.8")
}

dependencies {
  compileOnly(project(":core"))
  paperweightDevelopmentBundle("io.papermc.paper:dev-bundle:1.19.2-R0.1-SNAPSHOT")
}

If you need build scan or other information, tell me. I will post it too.

I am able to successfully resolve com.gitlab.exmserver:mol:main-SNAPSHOT via the maven repo https://jitpack.io. However, there is no main/default jar artifact for this publication. This is because you are publishing the shadow jar, which by default has a classifier of all. You can see the -all jar when listing the maven repo’s contents.

Changing your dependency declaration to implementation "com.gitlab.exmserver:mol:main-SNAPSHOT:all" will resolve the -all jar.

1 Like

Thanks, you are my life-saver!
I asked this question in many places, but this is the only one that I’ve got solution!

1 Like