Skip to content

Commit

Permalink
Compile against Java 17 (#5162)
Browse files Browse the repository at this point in the history
* build: use Java 17 for compilation

* build: compile using Java 17 release level

* doc: update README to reference Java 17

* ci: use Java 17 builder

* chore: update junit to 5.10 and mockito to 5.6

* test: fix PojoEventSystemTests under Java 17

* test: fix EventSystemReplayImplTest under Java 17
  • Loading branch information
BenjaminAmos authored Nov 17, 2023
1 parent 84228c1 commit 3aa68c0
Show file tree
Hide file tree
Showing 16 changed files with 36 additions and 27 deletions.
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 {

}

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 {

}
}
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

0 comments on commit 3aa68c0

Please sign in to comment.