-
-
Notifications
You must be signed in to change notification settings - Fork 86
/
build.gradle.kts
167 lines (132 loc) · 4.25 KB
/
build.gradle.kts
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import xyz.wagyourtail.jvmdg.gradle.task.DowngradeJar
import xyz.wagyourtail.jvmdg.gradle.task.ShadeJar
import java.io.ByteArrayOutputStream
plugins {
java
`maven-publish`
id("xyz.wagyourtail.jvmdowngrader")
}
allprojects {
apply(plugin = "java")
group = "com.leonardobishop"
version = "3.15.2"
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}
}
subprojects {
tasks.withType<JavaCompile> {
options.compilerArgs = listOf("-Xlint:deprecation", "-Xlint:unchecked")
options.encoding = Charsets.UTF_8.name()
options.release = 21
}
tasks.withType<Javadoc> {
options.encoding = Charsets.UTF_8.name()
}
tasks.withType<ProcessResources> {
filteringCharset = Charsets.UTF_8.name()
}
}
defaultTasks = mutableListOf("clean", "allJar")
tasks.register<Jar>("allJar") {
subprojects {
dependsOn.add(tasks.build)
}
if (project.findProperty("gitversion") == null || project.findProperty("gitversion") == "true") {
val gitCommitHash = gitCommitHash()
allprojects {
version = "${version}-${gitCommitHash}"
}
}
subprojects {
configurations.archives {
allArtifacts.files.forEach {
from(zipTree(it))
}
}
}
archiveBaseName = "Quests"
}
fun gitCommitHash(): String {
val outputStream = ByteArrayOutputStream()
project.exec {
commandLine = "git rev-parse --verify --short HEAD".split(" ")
standardOutput = outputStream
}
val gitCommitHashBytes = outputStream.toByteArray()
return String(gitCommitHashBytes).trim()
}
val javaVersions = listOf(
// from 1.12 to 1.16.5
JavaVersion.VERSION_1_8,
// just because it's a LTS version and a lot of servers use it
// https://en.wikipedia.org/wiki/Java_version_history
// https://bstats.org/global/bukkit#javaVersion
//
// also Paper recommends it
// https://docs.papermc.io/paper/getting-started#requirements
JavaVersion.VERSION_11,
// from 1.17 to 1.17.1
JavaVersion.VERSION_16,
// from 1.18 to 1.20.4
JavaVersion.VERSION_17
)
for (javaVersion in javaVersions) {
val allJarTask = tasks.getByName<Jar>("allJar")
// we use this hacky solution to improve display and sort order in IntelliJ Gradle tab
val majorVersion = javaVersion.ordinal + 1
val majorVersionFormatted = String.format("%02d", majorVersion)
val downgradeTaskName = "downgrade${majorVersionFormatted}AllJar"
tasks.register<DowngradeJar>(downgradeTaskName) {
inputFile = allJarTask.archiveFile
downgradeTo = javaVersion
quiet = true
archiveBaseName = "Quests"
archiveClassifier = "downgraded-${majorVersion}"
}
val downgradeJarTask = tasks.getByName<DowngradeJar>(downgradeTaskName)
val shadeTaskName = "shade${majorVersionFormatted}Downgrade"
tasks.register<ShadeJar>(shadeTaskName) {
inputFile = downgradeJarTask.archiveFile
downgradeTo = javaVersion
quiet = true
archiveBaseName = "Quests"
archiveClassifier = "downgraded-${majorVersion}-shaded"
shadePath = { _ -> "com/leonardobishop/quests/jvmdg" }
}
defaultTasks.add(shadeTaskName)
}
artifacts {
val allJarTask = tasks.named("allJar")
archives(allJarTask)
}
publishing {
publications {
create<MavenPublication>("maven") {
groupId = "com.leonardobishop"
artifactId = "quests"
version = project.version.toString()
val allJarTask = tasks.named("allJar")
artifact(allJarTask)
pom {
dependencies {
clear()
}
}
}
}
repositories {
maven("https://repo.leonardobishop.com/releases/") {
credentials {
username = findPropertyString("mavenUser") ?: System.getenv("MAVEN_USER")
password = findPropertyString("mavenPassword") ?: System.getenv("MAVEN_PASSWORD")
}
}
}
}
fun findPropertyString(propertyName: String): String? {
val propertyValue = project.findProperty(propertyName)
return if (propertyValue is String) propertyValue else null
}