Skip to content

Commit 285ba2f

Browse files
authored
build: convert engine-tests build.gradle to kotlin (#5202)
* engine-tests, prepare gradle kotlin. * engine-tests, gradle kotlin.
1 parent 20da7f2 commit 285ba2f

File tree

1 file changed

+46
-60
lines changed

1 file changed

+46
-60
lines changed

engine-tests/build.gradle engine-tests/build.gradle.kts

+46-60
Original file line numberDiff line numberDiff line change
@@ -2,63 +2,52 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
// Engine tests are split out due to otherwise quirky project dependency issues with module tests extending engine tests
5-
65
plugins {
7-
id "java-library"
8-
id "org.jetbrains.gradle.plugin.idea-ext"
9-
id "terasology-common"
6+
id("java-library")
7+
id("org.jetbrains.gradle.plugin.idea-ext")
8+
id("terasology-common")
109
}
1110

1211
// Grab all the common stuff like plugins to use, artifact repositories, code analysis config
13-
apply from: "$rootDir/config/gradle/publish.gradle"
14-
15-
import groovy.json.JsonSlurper
12+
apply(from = "$rootDir/config/gradle/publish.gradle")
1613

17-
ext {
18-
// Read environment variables, including variables passed by jenkins continuous integration server
19-
env = System.getenv()
20-
}
14+
// Read environment variables, including variables passed by jenkins continuous integration server
15+
val env = System.getenv()
2116

2217
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2318
// Java Section //
2419
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2520

2621
// Read the internal version out of the engine-tests module.txt
27-
def moduleFile = file('src/main/resources/org/terasology/unittest/module.txt')
28-
29-
if (!moduleFile.exists()) {
30-
println "Failed to find module.txt for engine-tests"
31-
throw new GradleException("Failed to find module.txt for engine-tests")
32-
}
22+
val moduleFile = layout.projectDirectory.file("src/main/resources/org/terasology/unittest/module.txt").asFile
3323

34-
println "Scanning for version in module.txt for engine-tests"
35-
def slurper = new JsonSlurper()
36-
def moduleConfig = slurper.parseText(moduleFile.text)
24+
println("Scanning for version in module.txt for engine-tests")
25+
val moduleConfig = groovy.json.JsonSlurper().parseText(moduleFile.readText()) as Map<String, String>
3726

3827
// Gradle uses the magic version variable when creating the jar name (unless explicitly set differently)
39-
version = moduleConfig.version
28+
version = moduleConfig["version"]!!
4029

4130
// Jenkins-Artifactory integration catches on to this as part of the Maven-type descriptor
42-
group = 'org.terasology.engine'
31+
group = "org.terasology.engine"
4332

44-
println "Version for $project.name loaded as $version for group $group"
33+
println("Version for $project.name loaded as $version for group $group")
4534

46-
sourceSets {
35+
configure<SourceSetContainer> {
4736
// Adjust output path (changed with the Gradle 6 upgrade, this puts it back)
48-
main.java.destinationDirectory = new File("$buildDir/classes")
49-
test.java.destinationDirectory = new File("$buildDir/testClasses")
37+
main { java.destinationDirectory.set(layout.buildDirectory.dir("classes")) }
38+
test { java.destinationDirectory.set(layout.buildDirectory.dir("testClasses")) }
5039
}
5140

5241
// Primary dependencies definition
5342
dependencies {
5443
// Dependency on the engine itself
55-
implementation project(':engine')
44+
implementation(project(":engine"))
5645

5746
// Dependency not provided for modules, but required for module-tests
58-
implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
59-
implementation group: 'org.codehaus.plexus', name: 'plexus-utils', version: '3.0.16'
60-
implementation group: 'com.google.protobuf', name: 'protobuf-java', version: '3.16.1'
61-
implementation "org.terasology:reflections:0.9.12-MB"
47+
implementation("com.google.code.gson:gson:2.8.6")
48+
implementation("org.codehaus.plexus:plexus-utils:3.0.16")
49+
implementation("com.google.protobuf:protobuf-java:3.16.1")
50+
implementation("org.terasology:reflections:0.9.12-MB")
6251

6352
implementation("org.terasology.joml-ext:joml-test:0.1.0")
6453

@@ -77,7 +66,7 @@ dependencies {
7766
api("com.google.truth:truth:1.1.3") {
7867
because("we provide some helper classes")
7968
}
80-
implementation('org.mockito:mockito-core:5.6.0') {
69+
implementation("org.mockito:mockito-core:5.6.0") {
8170
because("classes like HeadlessEnvironment use mocks")
8271
}
8372
constraints {
@@ -90,47 +79,44 @@ dependencies {
9079
}
9180

9281
//TODO: Remove it when gestalt will can to handle ProtectionDomain without classes (Resources)
93-
task copyResourcesToClasses(type:Copy) {
94-
from tasks.named("processResources")
95-
into sourceSets.main.output.classesDirs.first()
82+
tasks.register<Copy>("copyResourcesToClasses") {
83+
from("processResources")
84+
into(sourceSets["main"].output.classesDirs.first())
9685
}
9786

98-
tasks.named("compileJava"){
99-
dependsOn(copyResourcesToClasses)
87+
tasks.named("compileJava") {
88+
dependsOn("copyResourcesToClasses")
10089
}
10190

102-
jar { // Workaround about previous copy to classes. idk why engine-tests:jar called before :engine ...
103-
duplicatesStrategy = "EXCLUDE"
91+
tasks.withType<Jar> {
92+
// Workaround about previous copy to classes. idk why engine-tests:jar called before :engine ...
93+
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
10494
}
10595

106-
test {
107-
dependsOn rootProject.extractNatives
108-
109-
description("Runs all tests (slow)")
110-
96+
tasks.named<Test>("test") {
97+
dependsOn(tasks.getByPath(":extractNatives"))
98+
description = "Runs all tests (slow)"
99+
useJUnitPlatform ()
111100
systemProperty("junit.jupiter.execution.timeout.default", "4m")
112101
}
113102

114-
task unitTest(type: Test) {
115-
dependsOn rootProject.extractNatives
116-
117-
group "Verification"
118-
description("Runs unit tests (fast)")
119-
103+
tasks.register<Test>("unitTest") {
104+
dependsOn(tasks.getByPath(":extractNatives"))
105+
group = "Verification"
106+
description = "Runs unit tests (fast)"
120107
useJUnitPlatform {
121-
excludeTags "MteTest", "TteTest"
108+
excludeTags = setOf("MteTest", "TteTest")
122109
}
123110
systemProperty("junit.jupiter.execution.timeout.default", "1m")
124111
}
125112

126-
task integrationTest(type: Test) {
127-
dependsOn rootProject.extractNatives
128-
129-
group "Verification"
130-
description("Runs integration tests (slow) tagged with 'MteTest' or 'TteTest'")
113+
tasks.register<Test>("integrationTest") {
114+
dependsOn(tasks.getByPath(":extractNatives"))
115+
group = "Verification"
116+
description = "Runs integration tests (slow) tagged with 'MteTest' or 'TteTest'"
131117

132118
useJUnitPlatform {
133-
includeTags "MteTest", "TteTest"
119+
includeTags = setOf("MteTest", "TteTest")
134120
}
135121
systemProperty("junit.jupiter.execution.timeout.default", "5m")
136122
}
@@ -139,8 +125,8 @@ idea {
139125
module {
140126
// Change around the output a bit
141127
inheritOutputDirs = false
142-
outputDir = file('build/classes')
143-
testOutputDir = file('build/testClasses')
144-
downloadSources = true
128+
outputDir = file("build/classes")
129+
testOutputDir = file("build/testClasses")
130+
isDownloadSources = true
145131
}
146132
}

0 commit comments

Comments
 (0)