Kotlin Modules?

Matt Helliwell

New Member
Has anyone successfully got a module developed in Kotlin? I'm trying to write a Kotlin world generator(I have enough of Java a work!). The module builds ok but when run the game I get the error below.

I've played around adding Kotlin dependencies on the PC and Engine projects but without any joy. Has anyone any suggestions on the best way forward?

java.lang.NoClassDefFoundError: kotlin/jvm/internal/Intrinsics
at org.terasology.greatBritain.SurfaceProvider.process(SurfaceProvider.kt)
at org.terasology.world.generation.RegionImpl.lambda$getFacet$1(RegionImpl.java:49)
at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
at java.util.Iterator.forEachRemaining(Iterator.java:116)
at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
at org.terasology.world.generation.RegionImpl.getFacet(RegionImpl.java:48)
at org.terasology.logic.spawner.AbstractSpawner.findSpawnPosition(AbstractSpawner.java:51)
at org.terasology.logic.spawner.FixedSpawner.getSpawnPosition(FixedSpawner.java:49)
at org.terasology.world.generator.WorldGenerator.getSpawnPosition(WorldGenerator.java:49)
at org.terasology.logic.players.PlayerSystem.onConnect(PlayerSystem.java:151)
at org.terasology.logic.players.PlayerSystemMethodAccess.invoke(Unknown Source)
at org.terasology.entitySystem.event.internal.EventSystemImpl$ByteCodeEventHandlerInfo.invoke(EventSystemImpl.java:506)
at org.terasology.entitySystem.event.internal.EventSystemImpl.sendStandardEvent(EventSystemImpl.java:269)
at org.terasology.entitySystem.event.internal.EventSystemImpl.send(EventSystemImpl.java:260)
at org.terasology.entitySystem.entity.internal.BaseEntityRef.send(BaseEntityRef.java:145)
at org.terasology.network.internal.NetworkSystemImpl.connectClient(NetworkSystemImpl.java:831)
at org.terasology.network.internal.NetworkSystemImpl.joinLocal(NetworkSystemImpl.java:301)
at org.terasology.engine.modes.loadProcesses.SetupLocalPlayer.step(SetupLocalPlayer.java:44)
at org.terasology.engine.modes.StateLoading.update(StateLoading.java:242)
at org.terasology.engine.TerasologyEngine.tick(TerasologyEngine.java:435)
at org.terasology.engine.TerasologyEngine.mainLoop(TerasologyEngine.java:400)
at org.terasology.engine.TerasologyEngine.run(TerasologyEngine.java:376)
at org.terasology.engine.Terasology.main(Terasology.java:153)
Caused by: java.lang.ClassNotFoundException: Failed to find or load class kotlin.jvm.internal.Intrinsics
at org.terasology.module.sandbox.ModuleClassLoader.findClass(ModuleClassLoader.java:158)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at org.terasology.module.sandbox.ModuleClassLoader.loadClass(ModuleClassLoader.java:121)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 30 common frames omitted
Caused by: javassist.NotFoundException: kotlin.jvm.internal.Intrinsics
at javassist.ClassPool.get(ClassPool.java:452)
at org.terasology.module.sandbox.ModuleClassLoader$1.run(ModuleClassLoader.java:145)
at org.terasology.module.sandbox.ModuleClassLoader$1.run(ModuleClassLoader.java:142)
at java.security.AccessController.doPrivileged(Native Method)
at org.terasology.module.sandbox.ModuleClassLoader.findClass(ModuleClassLoader.java:142)
 

Cervator

Org Co-Founder & Project Lead
Contributor
Design
Logistics
SpecOps
So two potential things to investigate here:
  1. Our engine's sandboxing will wall off anything not inside a module or on the whitelist, with the usual result being a NoClassDefFoundError - see https://github.com/MovingBlocks/Terasology/wiki/Modding-API for a bit of added detail. So probably you just need to add a few things like kotlin.jvm.internal.Intrinsics to the whitelist if that seems a fair thing to put on there :)
  2. Kotlin and Scala modules have both been prototyped, but require subtly different build.gradle files to hook up the Kotlin or Scala. The two repos on GitHub should contain working versions - and you probably already have that in place since you got that far. I've got a newer build.gradle-less module approach working locally that simply sets the language via flag in module.txt but it breaks a bunch of other stuff.
 

Matt Helliwell

New Member
I've got it going - I've added the package "kotlin.jvm.internal" to ExternalApiWhitelist#PACKAGES and added the Kotlin libs as a dependency to the engine project. That'll allow me to carry on prototyping my module. Once I've understood things a bit better I can create a pull request for the engine changes if no-one else beats me to it.
 
Top