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

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

Open
Hiiragi283 opened this issue Nov 6, 2023 · 24 comments

Comments

@Hiiragi283
Copy link

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

@Hummel009
Copy link

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?

@slava110
Copy link

slava110 commented Feb 4, 2024

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

@Hiiragi283
Copy link
Author

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

@eigenraven
Copy link
Member

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
Copy link
Member

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

@Hiiragi283
Copy link
Author

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

@eigenraven
Copy link
Member

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

@Hiiragi283
Copy link
Author

Can i use GTNHGradle for MC1.12.2?

@slava110
Copy link

slava110 commented Feb 5, 2024

@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

@ghost
Copy link

ghost commented Apr 19, 2024

Any updates on this, found any workarounds?

@ghost
Copy link

ghost commented Apr 19, 2024

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

@Glease
Copy link

Glease commented Apr 19, 2024

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

@Glease Glease closed this as completed Apr 19, 2024
@ghost
Copy link

ghost commented Apr 19, 2024

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

@Glease
Copy link

Glease commented Apr 19, 2024

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?

@ghost
Copy link

ghost commented Apr 19, 2024

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

@ghost
Copy link

ghost commented Apr 19, 2024

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"?

@Glease
Copy link

Glease commented Apr 19, 2024

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

@Glease Glease reopened this Apr 19, 2024
@Glease
Copy link

Glease commented Apr 19, 2024

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

@ghost
Copy link

ghost commented Apr 19, 2024

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

@Hummel009
Copy link

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.

@ghost
Copy link

ghost commented Apr 20, 2024

@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

@ghost
Copy link

ghost commented Apr 20, 2024

@Hummel009
Copy link

Yes, compiler K2 works perfect with retrofuturagradle. Thanks!

@Hummel009
Copy link

Hummel009 commented May 23, 2024

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.

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

5 participants