Repository navigation
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
137 lines (121 loc) · 4.87 KB
/
Copy pathbuild.gradle.kts
File metadata and controls
137 lines (121 loc) · 4.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
import org.gradle.api.tasks.testing.logging.TestLogEvent.FAILED
import xyz.jpenilla.runpaper.task.RunServer
plugins {
alias(libs.plugins.codecov)
jacoco
id("buildlogic.common")
id("com.gradleup.nmcp.aggregation") version "1.6.2"
id("xyz.jpenilla.run-paper") version "3.1.0"
}
val rootVersion: String = (extra.properties["rootVersion"] as? String) ?: "2.16.2"
val snapshot: String = (extra.properties["snapshot"] as? String) ?: "SNAPSHOT"
var revision: String = (extra.properties["revision"] as? String) ?: ""
var buildNumber: String = (extra.properties["buildNumber"] as? String) ?: ""
var date: String = (extra.properties["date"] as? String) ?: ""
// Get Git metadata during build setup using the Git CLI.
// This replaces Grgit/JGit so the build stays compatible with Gradle's configuration cache.
// The result is recorded as a build input and can be reused without re-running Git each time.
// We keep the short hash length the same as before for consistency.
fun gitOutput(vararg args: String): String =
providers.exec {
commandLine("git", *args)
workingDir = rootDir
}.standardOutput.asText.get().trim()
date = gitOutput("show", "-s", "--format=%cd", "--date=format:%y.%m.%d", "HEAD")
revision = "-" + gitOutput("rev-parse", "--short=7", "HEAD")
buildNumber = if (project.hasProperty("buildnumber")) {
snapshot + "-" + (project.findProperty("buildnumber") as? String ?: "")
} else {
(project.findProperty("snapshot") as? String) ?: snapshot
}
extra.set("rootVersion", rootVersion)
extra.set("snapshot", snapshot)
extra.set("revision", revision)
extra.set("buildNumber", buildNumber)
extra.set("date", date)
version = String.format("%s-%s", rootVersion, snapshot)
if (!project.hasProperty("gitCommitHash")) {
ext["gitCommitHash"] = try {
gitOutput("rev-parse", "--short=7", "HEAD")
} catch (e: Exception) {
logger.warn("Error getting commit hash", e)
"no.git.id"
}
}
val totalReport = tasks.register<JacocoReport>("jacocoTotalReport") {
description = "Generates a combined JaCoCo coverage report for all subprojects."
for (proj in subprojects) {
proj.pluginManager.apply("jacoco")
proj.plugins.withId("java") {
executionData(
fileTree(proj.layout.buildDirectory).include("**/jacoco/*.exec")
)
sourceSets(proj.the<JavaPluginExtension>().sourceSets["main"])
reports {
xml.required.set(true)
xml.outputLocation.set(rootProject.layout.buildDirectory.file("reports/jacoco/report.xml"))
html.required.set(true)
}
dependsOn(proj.tasks.named("test"))
}
}
}
afterEvaluate {
totalReport.configure {
classDirectories.setFrom(classDirectories.files.map {
fileTree(it).apply {
exclude("**/*AutoValue_*")
exclude("**/*Registration.*")
}
})
}
}
codecov {
reportTask.set(totalReport)
}
allprojects {
tasks.withType<JavaCompile>().configureEach {
options.compilerArgs.addAll(arrayOf("-Xmaxerrs", "1000"))
}
tasks.withType<Test>().configureEach {
maxParallelForks = (Runtime.getRuntime().availableProcessors() / 2).takeIf { it > 0 } ?: 1
testLogging {
events(FAILED)
exceptionFormat = FULL
showExceptions = true
showCauses = true
showStackTraces = true
}
}
}
val supportedVersions: List<String> = listOf("1.21", "1.21.1", "1.21.4", "1.21.5",
"1.21.8", "1.21.10", "1.21.11", "26.1.2", "26.2", "26.3")
tasks {
supportedVersions.forEach {
register<RunServer>("runServer-$it") {
description = "Run a Paper server version $it."
minecraftVersion(it)
pluginJars(*project(":worldedit-bukkit").getTasksByName("shadowJar", false).map { (it as Jar).archiveFile }
.toTypedArray())
jvmArgs("-DPaper.IgnoreJavaVersion=true", "-Dcom.mojang.eula.agree=true", "--add-modules=jdk.incubator.vector")
group = "run paper"
runDirectory.set(file("run-$it"))
}
}
runServer<RunServer> {
description = "Run a Paper server for the latest supported Minecraft version (${supportedVersions.last()})."
minecraftVersion(supportedVersions.last())
pluginJars(*project(":worldedit-bukkit").getTasksByName("shadowJar", false).map { (it as Jar).archiveFile }
.toTypedArray())
jvmArgs("-Dcom.mojang.eula.agree=true")
}
}
nmcpAggregation {
centralPortal {
publishingType = "AUTOMATIC"
username = providers.gradleProperty("mavenCentralUsername")
password = providers.gradleProperty("mavenCentralPassword")
}
publishAllProjectsProbablyBreakingProjectIsolation()
}