RetroFuturaGradle icon indicating copy to clipboard operation
RetroFuturaGradle copied to clipboard

Error when calling vanilla or Forge classes from dependency library in kotlin environment

Open Hiiragi283 opened this issue 2 years ago • 24 comments
trafficstars

Example:

val stack: ItemStack = ItemStack(Items.IRON_INGOT)
crafttweaker.api.minecraft.CraftTweakerMC.getItemStack(stack) <-

Error Message: Cannot access class 'net.minecraft.item.ItemStack'. Check your module classpath for missing or conflicting dependencies

Hiiragi283 avatar Nov 06 '23 08:11 Hiiragi283

I'm facing the same problem. I fixed it temporarily by putting the dependency source code in the build/rfg/minecraft-src folder. However, this is a bad way, because the decompiled dependency source contains errors.

Maybe you managed to solve this problem in a better way during these 2 months?

hummel009 avatar Dec 22 '23 09:12 hummel009

Same problem. Wasn't happening before to me IIRC, I've been using RFG earlier with Kotlin without problems :I

slava110 avatar Feb 04 '24 14:02 slava110

@slava110 oh really? i didn’t know that solution

Hiiragi283 avatar Feb 04 '24 23:02 Hiiragi283

Have a look at https://github.com/GTNewHorizons/MX-Random/blob/master/addon.gradle - it builds with latest RFG using the GTNH buildscript without issues and is a kotlin mod.

eigenraven avatar Feb 04 '24 23:02 eigenraven

And if that doesn't help, please send a code sample or repository I can actually test to see what's going on

eigenraven avatar Feb 04 '24 23:02 eigenraven

Have a look at https://github.com/GTNewHorizons/MX-Random/blob/master/addon.gradle - it builds with latest RFG using the GTNH buildscript without issues and is a kotlin mod.

well… is that project using RFG? i couldn’t find any reference in *.gradle files

Hiiragi283 avatar Feb 04 '24 23:02 Hiiragi283

Yes, almost all GTNH projects use RFG. We now switched to GTNHGradle which uses RFG as a dependency, but you can look at the old buildscript here https://github.com/GTNewHorizons/MX-Random/blob/8a6903997e9c34e991f607554d179367c3d8d3b6/build.gradle

eigenraven avatar Feb 04 '24 23:02 eigenraven

Can i use GTNHGradle for MC1.12.2?

Hiiragi283 avatar Feb 05 '24 01:02 Hiiragi283

@eigenraven I've created minimal reproducible example here: https://github.com/slava110/RFGKotlinProblem I'm depending on CreativeCore mod with rfg.deobf on it here After initial setup you will (probably) be able to see error in ExampleMod.kt file like this one: image

slava110 avatar Feb 05 '24 01:02 slava110

Any updates on this, found any workarounds?

shorinami avatar Apr 19 '24 02:04 shorinami

Yes, almost all GTNH projects use RFG. We now switched to GTNHGradle which uses RFG as a dependency, but you can look at the old buildscript here https://github.com/GTNewHorizons/MX-Random/blob/8a6903997e9c34e991f607554d179367c3d8d3b6/build.gradle

That project has same problem image

shorinami avatar Apr 19 '24 03:04 shorinami

Try run gradlew setupDecompWorkspace. I got the same issue on your test repo before running that command. The issue gies away afterwards.

Glease avatar Apr 19 '24 03:04 Glease

Try run gradlew setupDecompWorkspace. I got the same issue on your test repo before running that command. The issue gies away afterwards.

I did run it, does not help

shorinami avatar Apr 19 '24 03:04 shorinami

If anything,

  • I bumped gradle version in gradlew setting to 8.6
  • I'm running gradle with java 17
  • I'm using intellij 2023.3.x, with RFG enabled version of minecraftdev plugin

I don't think any of these would practically matter, but that's probably the only outstanding points

also can you build the project by running gradlew build?

Glease avatar Apr 19 '24 03:04 Glease

If anything,

  • I bumped gradle version in gradlew setting to 8.6

  • I'm running gradle with java 17

  • I'm using intellij 2023.3.x, with RFG enabled version of minecraftdev plugin

I don't think any of these would practically matter, but that's probably the only outstanding points

also can you build the project by running gradlew build?

Yes, the project builds just fine, also if I access the library from java, it works just fine (without no warnings/errors), so it is related to how IDEA handles Kotlin I think. Will check the other stuff and let you know if that helps

shorinami avatar Apr 19 '24 03:04 shorinami

If anything,

  • I bumped gradle version in gradlew setting to 8.6
  • I'm running gradle with java 17
  • I'm using intellij 2023.3.x, with RFG enabled version of minecraftdev plugin

I don't think any of these would practically matter, but that's probably the only outstanding points

also can you build the project by running gradlew build?

Did not help, rolled back to 2023.3.6, java 17, gradle 8.6. Only thing I did not understand fully, what do you mean by "RFG enabled"?

shorinami avatar Apr 19 '24 05:04 shorinami

https://github.com/eigenraven/MinecraftDev as opposed to the one you would find on plugin marketplace

Glease avatar Apr 19 '24 05:04 Glease

How about gradlew clean and delete .idea folder (while IDE is closed of course)?

Glease avatar Apr 19 '24 05:04 Glease

How about gradlew clean and delete .idea folder (while IDE is closed of course)?

Yeah, same setup, same problem (tried different projects, recloning, invalidating cache, etc): image

shorinami avatar Apr 19 '24 06:04 shorinami

Still have the same problem. I tried different Kotlin (1.8.22 — 1.9.23) + Gradle (8.2 — 8.7) + system-wide JDK (1.8 — 21), and nothing helped.

The problem can be solved in bad way, to decompile the .jar dependency and to put its classes into rfg/minecraft-src. But you know, the quality of decompiled dependencies is low.

hummel009 avatar Apr 19 '24 13:04 hummel009

@Hummel009 @Glease So I figured out an interesting fix for that. After turning on the Kotlin K2 Mode in Kotlin language settings the issue is gone.

image

shorinami avatar Apr 20 '24 00:04 shorinami

I also filled out an issue on the JetBrains YouTrack as it might be an issue on their end: https://youtrack.jetbrains.com/issue/IDEA-352220/Cannot-access-class-net.minecraftforge.fml.common.event.FMLServerStartingEvent.-Check-your-module-classpath-for-missing-or

shorinami avatar Apr 20 '24 00:04 shorinami

Yes, compiler K2 works perfect with retrofuturagradle. Thanks!

hummel009 avatar Apr 27 '24 15:04 hummel009

With the release of Kotlin 2.0, the error did not disappear on its own (although the developers report that the compiler is now used by default). Apparently, the “K2 Mode” checkbox does something different. So we'll have to wait a while longer before everything works as it should. Because at the moment, unfortunately, enabling this checkbox breaks a lot of other plugins.

hummel009 avatar May 23 '24 11:05 hummel009