Scalable Cat's Force

Scalable Cat's Force

26M Downloads

NoClassDefFoundError for 3rd party scala dependencies

ControlNet opened this issue ยท 1 comments

commented

Hi,

I'm porting my mod to 1.18 with Forge 40.1.0, but have problem of NoClassDefFoundError for 3rd party scala library.

Reproduce steps:

  1. Use your SLP-example repository.
  2. Add random scala dependencies to gradle. For example,
    • implementation(group: "org.json4s", name: "json4s-native_2.13", version: "4.1.0-M1")
  3. Use this library in ExampleMod.scala as below.
package com.example.examplemod

import net.minecraftforge.fml.common.Mod
import org.apache.logging.log4j.LogManager
import org.json4s.native.JsonMethods._

@Mod(ExampleMod.MOD_ID)
object ExampleMod {
  final val MOD_ID = "examplemod"
  private val LOGGER = LogManager.getLogger
  LOGGER.info(parse(""" { "numbers" : [1, 2, 3, 4] } """))
}
  1. Run gradle runClient, and it will throw Suppressed: java.lang.NoClassDefFoundError: org/json4s/native/JsonMethods$

I tested with multiple external scala libraries and did some experiments to solve it.

  1. Copy-paste the source code of external libraries to the local project. It will be load successfully.
  2. Build Jar shadowing the external libraries, and it will be OK.

But these solutions aren't good to use in development. Do you have any better idea to deal with it?

commented

See this example from kotlin loader.

https://github.com/thedarkcolour/KotlinForForge/blob/site/thedarkcolour/kotlinforforge/gradle/kff-3.3.2.gradle#L18-L28
https://github.com/thedarkcolour/KotlinForForge/blob/site/thedarkcolour/kotlinforforge/gradle/kff-3.3.2.gradle#L44-L48

Create new configuration and add libraries to it. Then add them to runtime classpath as the example shows in line 24-28.