Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoClassDefFoundError for 3rd party scala dependencies #16

Closed
ControlNet opened this issue May 2, 2022 · 1 comment
Closed

NoClassDefFoundError for 3rd party scala dependencies #16

ControlNet opened this issue May 2, 2022 · 1 comment

Comments

@ControlNet
Copy link

ControlNet commented May 2, 2022

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?

@Kotori316
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants