MovingBlocks / Terasology

Terasology - open source voxel world
http://terasology.org
Apache License 2.0
3.64k stars 1.33k forks source link

Terasology now uses Java 17 #5177

Closed BenjaminAmos closed 3 months ago

BenjaminAmos commented 7 months ago

Documentation Topic

As of #5162 being merged, Terasology now uses Java 17 for compilation. Whilst some documentation has been updated for this, there is likely more still that references Java 11 in places.

After pulling in 3aa68c04f192243575f7f78de5b6ce268bb2da1a, or with a fresh clone, you will need a Java 17 JDK to build and run the game. JDK 17 can be obtained from many sources. I personally find that the Eclipse Termurin (formerly AdoptOpenJDK) distribution tends to work.

If you are seeing errors like the following then you are probably still using JDK 11. You need to update to JDK 17 to fix this (make sure to update the JAVA_HOME environment variable as well).

A problem occurred configuring root project 'Terasology'.
> Could not determine the dependencies of null.
   > Could not resolve all task dependencies for configuration ':classpath'.
      > Could not resolve org.terasology.gradology:build-logic.
        Required by:
            project :
         > No matching variant of project :build-logic was found. The consumer was configured to find a library for use during runtime, compatible with Java 11, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '8.4' but:
             - Variant 'apiElements' capability org.terasology.gradology:build-logic:unspecified declares a library, packaged as a jar, and its dependencies declared externally:
                 - Incompatible because this component declares a component for use during compile-time, compatible with Java 17 and the consumer needed a component for use during runtime, compatible with Java 11
                 - Other compatible attribute:
                     - Doesn't say anything about org.gradle.plugin.api-version (required '8.4')
             - Variant 'mainSourceElements' capability org.terasology.gradology:build-logic:unspecified declares a component, and its dependencies declared externally:
                 - Incompatible because this component declares a component of category 'verification' and the consumer needed a library
                 - Other compatible attributes:
                     - Doesn't say anything about its target Java version (required compatibility with Java 11)
                     - Doesn't say anything about its elements (required them packaged as a jar)
                     - Doesn't say anything about org.gradle.plugin.api-version (required '8.4')
                     - Doesn't say anything about its usage (required runtime)

You may also see the following warning. We're aware of it and it is unlikely to be resolved soon. The game depends on SecurityManager as a part of module sandboxing.

WARNING: A terminally deprecated method in java.lang.System has been called
WARNING: System::setSecurityManager has been called by org.terasology.engine.core.module.ModuleManager (file:/engine/build/libs/engine-5.4.0-SNAPSHOT.jar)
WARNING: Please consider reporting this to the maintainers of org.terasology.engine.core.module.ModuleManager
WARNING: System::setSecurityManager will be removed in a future release

Documentation Type

Terasology Knowledge Base

BenjaminAmos commented 7 months ago

@soloturn @PurityLake @lokytech5 @jdrueckert @skaldarnar - this might affect you.

jdrueckert commented 7 months ago

Provided @skaldarnar and I write a milestone summary blogpost again, that's definitely going in there in bold :sweat_smile:

soloturn commented 7 months ago

thanks for the heads up @BenjaminAmos ! as i never have a JAVA_HOME set i am wondering why you recommend to do so for terasology?

BenjaminAmos commented 7 months ago

thanks for the heads up @BenjaminAmos ! as i never have a JAVA_HOME set i am wondering why you recommend to do so for terasology?

I did not intend to recommend it, just to advise that the variable should be changed if it exists. When working with multiple Java versions, setting the JAVA_HOME environment variable can be an easy way to switch between versions. Certain tools used to depend on the presence of the variable to identify where Java was installed. Most of the time having the right java install directory in your system path (the PATH environment variable) works the same..

lokytech5 commented 7 months ago

May I know the actual Java version to set in JAVA_HOME?

BenjaminAmos commented 7 months ago

If you have a JAVA_HOME environment variable set then you should change it to the location that Java 17 is installed in. For example, on Windows it might be installed in C:\Program Files\Eclipse Adoptium\jdk-17.0.8.101-hotspot. If you don't have that environment variable present then you do not need to do anything with it.

lokytech5 commented 6 months ago

ok noted

soloturn commented 6 months ago

@BenjaminAmos , when exiting the game using "josharias survival" i get the following error:

11:16:51.570 [main] INFO  o.t.engine.core.TerasologyEngine - Shutting down Terasology...
11:16:51.595 [Chunk-Processing-Reactor] ERROR o.t.e.w.c.p.ChunkProcessingPipeline - Reactor thread was interrupted
java.lang.InterruptedException: null
        at java.base/java.util.concurrent.locks.ReentrantLock$Sync.lockInterruptibly(ReentrantLock.java:159)
        at java.base/java.util.concurrent.locks.ReentrantLock.lockInterruptibly(ReentrantLock.java:372)
        at java.base/java.util.concurrent.PriorityBlockingQueue.take(PriorityBlockingQueue.java:531)
        at org.terasology.engine.world.chunks.pipeline.ChunkExecutorCompletionService.take(ChunkExecutorCompletionService.java:83)
        at org.terasology.engine.world.chunks.pipeline.ChunkProcessingPipeline.chunkTaskHandler(ChunkProcessingPipeline.java:82)
        at java.base/java.lang.Thread.run(Thread.java:840)
11:16:51.703 [main] INFO  o.t.e.p.i.ReadWriteStorageManager - Saving - Creating game snapshot
11:16:51.780 [main] INFO  o.t.e.p.i.ReadWriteStorageManager - Saving - Snapshot created: Writing phase starts
11:16:51.815 [parallel-1] ERROR reactor.core.publisher.Operators - Operator called default onErrorDropped
reactor.core.Exceptions$ErrorCallbackNotImplemented: java.lang.reflect.InaccessibleObjectException: Unable to make field private final java.lang.Class java.lang.Class.componentType accessible: module java.base does not "opens java.lang" to unnamed module @f0da945
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field private final java.lang.Class java.lang.Class.componentType accessible: module java.base does not "opens java.lang" to unnamed module @f0da945
        at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
        at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
        at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:178)
        at java.base/java.lang.reflect.Field.setAccessible(Field.java:172)
        at org.terasology.persistence.typeHandling.coreTypes.factories.ObjectFieldMapTypeHandlerFactory.lambda$getResolvedFields$1(ObjectFieldMapTypeHandlerFactory.java:80)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
        at org.terasology.persistence.typeHandling.coreTypes.factories.ObjectFieldMapTypeHandlerFactory.getResolvedFields(ObjectFieldMapTypeHandlerFactory.java:68)
BenjaminAmos commented 6 months ago
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field private final java.lang.Class java.lang.Class.componentType accessible: module java.base does not "opens java.lang" to unnamed module @f0da945
        at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
        at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
        at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:178)
        at java.base/java.lang.reflect.Field.setAccessible(Field.java:172)
        at org.terasology.persistence.typeHandling.coreTypes.factories.ObjectFieldMapTypeHandlerFactory.lambda$getResolvedFields$1(ObjectFieldMapTypeHandlerFactory.java:80)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
        at org.terasology.persistence.typeHandling.coreTypes.factories.ObjectFieldMapTypeHandlerFactory.getResolvedFields(ObjectFieldMapTypeHandlerFactory.java:68)

There is likely a component somewhere that contains a java.lang.Class field within it. This does look like a Java 17 issue though.

I think this might have been related to RetainComponentsComponent when I last checked.

soloturn commented 3 months ago

nothing known which is open.