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

Compile against Java 17 #5162

Merged
merged 10 commits into from
Nov 17, 2023
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ properties([

pipeline {
agent {
label 'ts-engine && heavy && java11'
label 'ts-engine && heavy && java17'
}
stages {
// declarative pipeline does `checkout scm` automatically when hitting first stage
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ For more information about playing, like hot keys or server hosting, see the [de

### Alternative Installation Methods

If you already have a Java Development Kit (JDK) installed, you may use a direct download release as an alternative to using the [launcher](https://github.com/MovingBlocks/TerasologyLauncher/releases). Java version 11 is required.
If you already have a Java Development Kit (JDK) installed, you may use a direct download release as an alternative to using the [launcher](https://github.com/MovingBlocks/TerasologyLauncher/releases). Java version 17 is required.

Direct download stable builds are uploaded to [our release section here on GitHub](https://github.com/MovingBlocks/Terasology/releases) while the cutting-edge develop version can be downloaded direct [here from our Jenkins](https://jenkins.terasology.io/teraorg/job/Terasology/job/Omega/job/master/lastSuccessfulBuild/artifact/distros/omega/build/distributions/TerasologyOmega.zip).

Expand All @@ -132,7 +132,7 @@ Development is possible on all common platforms (Windows, Linux, MacOS) as long
### Requirements

Technical Requirements:
- Java SE Development Kit (JDK) 11. The CI will verify against this baseline version.
- Java SE Development Kit (JDK) 17. The CI will verify against this baseline version.
<br>Using newer Java versions may cause issues (see [#3976](https://github.com/MovingBlocks/Terasology/issues/3976)).
- Git to clone the repo and commit changes.

Expand Down
3 changes: 2 additions & 1 deletion build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

kotlin {
jvmToolchain(11)
jvmToolchain(17)
}

repositories {
Expand Down Expand Up @@ -37,6 +37,7 @@ dependencies {
constraints {
implementation("com.google.guava:guava:31.1-jre")
implementation("org.javassist:javassist:3.29.0-GA")
implementation("net.bytebuddy:bytebuddy:1.14.8")
}

// graph analysis
Expand Down
4 changes: 2 additions & 2 deletions build-logic/src/main/kotlin/terasology-metrics.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ dependencies {
testImplementation("org.junit.jupiter:junit-jupiter-params")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")

testImplementation("org.mockito:mockito-inline:3.12.4")
testImplementation("org.mockito:mockito-junit-jupiter:3.12.4")
testImplementation("org.mockito:mockito-core:5.6.0")
testImplementation("org.mockito:mockito-junit-jupiter:5.6.0")

testImplementation("com.google.truth:truth:1.1.3")
testImplementation("com.google.truth.extensions:truth-java8-extension:1.1.3")
Expand Down
11 changes: 5 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,13 @@ import org.terasology.gradology.CopyButNeverOverwrite
import static org.gradle.internal.logging.text.StyledTextOutput.Style

// Test for right version of Java in use for running this script
assert org.gradle.api.JavaVersion.current().isJava11Compatible()
if (!(JavaVersion.current() == JavaVersion.VERSION_11)) {
assert org.gradle.api.JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_17)
if (!(JavaVersion.current() == JavaVersion.VERSION_17)) {
def out = services.get(StyledTextOutputFactory).create("an-ouput")
out.withStyle(Style.FailureHeader).println("""
WARNING: Compiling with a JDK of not version 11. While some other Javas may be
safe to use, any newer than 11 may cause issues.
If you encounter oddities try Java 11.
See https://github.com/MovingBlocks/Terasology/issues/3976.
WARNING: Compiling with a JDK of not version 17. While some other Javas may be
safe to use, any newer than 17 may cause issues.
If you encounter oddities try Java 17.
Current detected Java version is ${JavaVersion.current()}
from vendor ${System.getProperty("java.vendor")}
located at ${System.getProperty("java.home")}
Expand Down
2 changes: 1 addition & 1 deletion config/gradle/common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ javadoc.options.encoding = 'UTF-8'

tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
options.release.set(11)
options.release.set(17)
}

task sourceJar(type: Jar) {
Expand Down
9 changes: 7 additions & 2 deletions engine-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ dependencies {


// Test lib dependencies
implementation(platform("org.junit:junit-bom:5.8.1")) {
implementation(platform("org.junit:junit-bom:5.10.0")) {
// junit-bom will set version numbers for the other org.junit dependencies.
}
api("org.junit.jupiter:junit-jupiter-api") {
Expand All @@ -81,9 +81,14 @@ dependencies {
api("com.google.truth:truth:1.1.3") {
because("we provide some helper classes")
}
implementation("org.mockito:mockito-inline:3.12.4") {
implementation('org.mockito:mockito-core:5.6.0') {
because("classes like HeadlessEnvironment use mocks")
}
constraints {
implementation("net.bytebuddy:bytebuddy:1.14.8") {
because("we need a newer bytebuddy version for Java 17")
}
}

// See terasology-metrics for other test-only internal dependencies
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,11 @@ TerasologyEngine createEngine(TerasologyEngineBuilder terasologyEngineBuilder) t

protected void mockPathManager() {
PathManager originalPathManager = PathManager.getInstance();
pathManager = Mockito.spy(originalPathManager);
if (!Mockito.mockingDetails(originalPathManager).isMock()) {
pathManager = Mockito.spy(originalPathManager);
} else {
pathManager = originalPathManager;
}
Mockito.when(pathManager.getModulePaths()).thenReturn(Collections.emptyList());
pathManagerCleaner = new PathManagerProvider.Cleaner(originalPathManager, pathManager);
PathManagerProvider.setPathManager(pathManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public void testEventReceiverRegistration() {
assertEquals(1, receiver.eventList.size());
}

private static class TestEvent extends AbstractConsumableEvent {
public static class TestEvent extends AbstractConsumableEvent {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does this have to be public now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Java 17 is a lot stricter about accessing private members via reflection. We were able to get away with this before under Java 11 because it only produced a warning.

java.lang.IllegalAccessError: failed to access class org.terasology.engine.entitySystem.PojoEventSystemTests$TestEvent from class org.terasology.engine.entitySystem.PojoEventSystemTests$TestEventHandlerMethodAccess (org.terasology.engine.entitySystem.PojoEventSystemTests$TestEvent is in unnamed module of loader 'app'; org.terasology.engine.entitySystem.PojoEventSystemTests$TestEventHandlerMethodAccess is in unnamed module of loader com.esotericsoftware.reflectasm.AccessClassLoader @319988b0)
	at org.terasology.engine.entitySystem.PojoEventSystemTests$TestEventHandlerMethodAccess.invoke(Unknown Source)
	at org.terasology.engine.entitySystem.event.internal.EventSystemImpl$ByteCodeEventHandlerInfo.invoke(EventSystemImpl.java:399)
	at org.terasology.engine.entitySystem.event.internal.EventSystemImpl.sendConsumableEvent(EventSystemImpl.java:274)
	at org.terasology.engine.entitySystem.event.internal.EventSystemImpl.send(EventSystemImpl.java:253)
	at org.terasology.engine.entitySystem.PojoEventSystemTests.testChildEvent(PojoEventSystemTests.java:164)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:728)
	at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
	at org.junit.jupiter.engine.extension.SameThreadTimeoutInvocation.proceed(SameThreadTimeoutInvocation.java:45)
	at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:156)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:147)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:86)
	at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(InterceptingExecutableInvoker.java:103)
	at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.lambda$invoke$0(InterceptingExecutableInvoker.java:93)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
	at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:92)
	at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:86)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$7(TestMethodTestDescriptor.java:218)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:214)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:139)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:69)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:151)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:107)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86)
	at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86)
	at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:119)
	at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access$000(JUnitPlatformTestClassProcessor.java:94)
	at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:89)
	at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:62)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
	at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
	at jdk.proxy1/jdk.proxy1.$Proxy2.stop(Unknown Source)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker$3.run(TestWorker.java:193)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.executeAndMaintainThreadName(TestWorker.java:129)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:100)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:60)
	at org.gradle.process.internal.worker.child.ActionExecutionWorker.execute(ActionExecutionWorker.java:56)
	at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:113)
	at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:65)
	at worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:69)
	at worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good 👍


}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public static class Received {
}
}

private static class TestEvent extends AbstractConsumableEvent {
public static class TestEvent extends AbstractConsumableEvent {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import org.terasology.nui.layouts.CardLayout;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import org.terasology.nui.util.RectUtility;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import org.terasology.nui.util.RectUtility;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ protected byte[] loadChunkZip(Vector3ic chunkPos) {
Vector3i chunkZipPos = storagePathProvider.getChunkZipPosition(chunkPos);
Path chunkPath = storagePathProvider.getChunkZipPath(chunkZipPos);
if (Files.isRegularFile(chunkPath)) {
try (FileSystem chunkZip = FileSystems.newFileSystem(chunkPath, null)) {
try (FileSystem chunkZip = FileSystems.newFileSystem(chunkPath, (ClassLoader) null)) {
Path targetChunk = chunkZip.getPath(storagePathProvider.getChunkFilename(chunkPos));
if (Files.isRegularFile(targetChunk)) {
chunkData = Files.readAllBytes(targetChunk);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ private void writeChunkStores() throws IOException {
Path oldChunkZipPath = storagePathProvider.getChunkZipPath(chunkZipPos);
final FileSystem zip = chunkZipEntry.getValue();
if (Files.isRegularFile(oldChunkZipPath)) {
try (FileSystem oldZip = FileSystems.newFileSystem(oldChunkZipPath, null)) {
try (FileSystem oldZip = FileSystems.newFileSystem(oldChunkZipPath, (ClassLoader) null)) {
for (Path root : oldZip.getRootDirectories()) {
Files.walkFileTree(root, new SimpleFileVisitor<>() {
@Override
Expand Down
Loading