-
Notifications
You must be signed in to change notification settings - Fork 190
/
build.gradle.kts
335 lines (287 loc) · 10.9 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
/*
* Minecraft Development for IntelliJ
*
* https://mcdev.io/
*
* Copyright (C) 2024 minecraft-dev
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, version 3.0 only.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import org.gradle.internal.jvm.Jvm
import org.jetbrains.changelog.Changelog
import org.jetbrains.gradle.ext.settings
import org.jetbrains.gradle.ext.taskTriggers
import org.jetbrains.intellij.platform.gradle.TestFrameworkType
import org.jetbrains.intellij.platform.gradle.tasks.PrepareSandboxTask
plugins {
groovy
id(libs.plugins.changelog.get().pluginId)
alias(libs.plugins.idea.ext)
`mcdev-core`
`mcdev-parsing`
`mcdev-publishing`
}
val coreVersion: String by project
val gradleToolingExtension: Configuration by configurations.creating
val testLibs: Configuration by configurations.creating {
isTransitive = false
}
group = "com.demonwav.mcdev"
val gradleToolingExtensionSourceSet: SourceSet = sourceSets.create("gradle-tooling-extension") {
configurations.named(compileOnlyConfigurationName) {
extendsFrom(gradleToolingExtension)
}
}
val gradleToolingExtensionJar = tasks.register<Jar>(gradleToolingExtensionSourceSet.jarTaskName) {
from(gradleToolingExtensionSourceSet.output)
archiveClassifier.set("gradle-tooling-extension")
exclude("META-INF/plugin.xml")
}
val templatesSourceSet: SourceSet = sourceSets.create("templates") {
resources {
srcDir("templates")
compileClasspath += sourceSets.main.get().output
}
}
val templateSourceSets: List<SourceSet> = (file("templates").listFiles() ?: emptyArray()).mapNotNull { file ->
if (file.isDirectory() && (file.listFiles() ?: emptyArray()).any { it.name.endsWith(".mcdev.template.json") }) {
sourceSets.create("templates-${file.name}") {
resources {
srcDir(file)
compileClasspath += sourceSets.main.get().output
}
}
} else {
null
}
}
val externalAnnotationsJar = tasks.register<Jar>("externalAnnotationsJar") {
from("externalAnnotations")
destinationDirectory.set(layout.buildDirectory.dir("externalAnnotations"))
archiveFileName.set("externalAnnotations.jar")
}
dependencies {
// Add tools.jar for the JDI API
implementation(files(Jvm.current().toolsJar))
implementation(files(gradleToolingExtensionJar))
implementation(libs.mixinExtras.expressions)
testLibs(libs.mixinExtras.common)
implementation(libs.mappingIo)
implementation(libs.bundles.asm)
implementation(libs.bundles.fuel)
intellijPlatform {
intellijIdeaCommunity(libs.versions.intellij.ide)
// Bundled plugin dependencies
bundledPlugin("com.intellij.java")
bundledPlugin("org.jetbrains.idea.maven")
bundledPlugin("com.intellij.gradle")
bundledPlugin("org.intellij.groovy")
bundledPlugin("ByteCodeViewer")
bundledPlugin("org.intellij.intelliLang")
bundledPlugin("com.intellij.properties")
// Optional dependencies
bundledPlugin("org.jetbrains.kotlin")
bundledPlugin("org.toml.lang")
bundledPlugin("org.jetbrains.plugins.yaml")
testFramework(TestFrameworkType.JUnit5)
testFramework(TestFrameworkType.Plugin.Java)
pluginVerifier()
}
testLibs(libs.test.mockJdk)
testLibs(libs.test.mixin)
testLibs(libs.test.spigotapi)
testLibs(libs.test.bungeecord)
testLibs(libs.test.spongeapi) {
artifact {
classifier = "shaded"
}
}
testLibs(libs.test.fabricloader)
testLibs(libs.test.nbt) {
artifact {
extension = "nbt"
}
}
testLibs(projects.mixinTestData)
// For non-SNAPSHOT versions (unless Jetbrains fixes this...) find the version with:
// afterEvaluate { println(intellij.ideaDependency.get().buildNumber.substring(intellij.type.get().length + 1)) }
gradleToolingExtension(libs.groovy)
gradleToolingExtension(libs.gradleToolingExtension)
gradleToolingExtension(libs.annotations)
}
changelog {
version = coreVersion
groups.empty()
path = "changelog.md"
}
intellijPlatform {
projectName = "Minecraft Development"
pluginVerification {
ides {
recommended()
}
}
}
tasks.patchPluginXml {
val changelog = project.changelog
changeNotes = changelog.render(Changelog.OutputType.HTML)
}
// Compile classes to be loaded into the Gradle VM to Java 5 to match Groovy
// This is for maximum compatibility, these classes will be loaded into every Gradle import on all
// projects (not just Minecraft), so we don't want to break that with an incompatible class version.
tasks.named(gradleToolingExtensionSourceSet.compileJavaTaskName, JavaCompile::class) {
val java7Compiler = javaToolchains.compilerFor { languageVersion.set(JavaLanguageVersion.of(11)) }
javaCompiler.set(java7Compiler)
options.release.set(6)
options.bootstrapClasspath = files(java7Compiler.map { it.metadata.installationPath.file("jre/lib/rt.jar") })
options.compilerArgs = listOf("-Xlint:-options")
}
tasks.withType<GroovyCompile>().configureEach {
options.compilerArgs = listOf("-proc:none")
sourceCompatibility = "1.5"
targetCompatibility = "1.5"
}
tasks.processResources {
for (lang in arrayOf("", "_en")) {
from("src/main/resources/messages.MinecraftDevelopment_en_US.properties") {
rename { "messages.MinecraftDevelopment$lang.properties" }
}
}
// These templates aren't allowed to be in a directory structure in the output jar
// But we have a lot of templates that would get real hard to deal with if we didn't have some structure
// So this just flattens out the fileTemplates/j2ee directory in the jar, while still letting us have directories
exclude("fileTemplates/j2ee/**")
from(fileTree("src/main/resources/fileTemplates/j2ee").files) {
eachFile {
relativePath = RelativePath(true, "fileTemplates", "j2ee", this.name)
}
}
}
tasks.test {
dependsOn(tasks.jar, testLibs)
testLibs.resolvedConfiguration.resolvedArtifacts.forEach {
systemProperty("testLibs.${it.name}", it.file.absolutePath)
}
systemProperty("NO_FS_ROOTS_ACCESS_CHECK", "true")
systemProperty("java.awt.headless", "true")
jvmArgs(
"-Dsun.io.useCanonCaches=false",
"-Dsun.io.useCanonPrefixCache=false",
)
}
idea {
project.settings.taskTriggers.afterSync("generate")
}
license {
val endings = listOf("java", "kt", "kts", "groovy", "gradle.kts", "xml", "properties", "html", "flex", "bnf")
exclude("META-INF/plugin.xml") // https://youtrack.jetbrains.com/issue/IDEA-345026
include(endings.map { "**/*.$it" })
val projectDir = layout.projectDirectory.asFile
exclude {
it.file.toRelativeString(projectDir)
.replace("\\", "/")
.startsWith("src/test/resources")
}
tasks {
register("gradle") {
files.from(
fileTree(project.projectDir) {
include("*.gradle.kts", "gradle.properties")
exclude("**/buildSrc/**", "**/build/**")
},
)
}
register("buildSrc") {
files.from(
project.fileTree(project.projectDir.resolve("buildSrc")) {
include("**/*.kt", "**/*.kts")
exclude("**/build/**")
},
)
}
register("mixinTestData") {
files.from(
project.fileTree(project.projectDir.resolve("mixin-test-data")) {
include("**/*.java", "**/*.kts")
exclude("**/build/**")
},
)
}
register("grammars") {
files.from(project.fileTree("src/main/grammars"))
}
register("externalAnnotations") {
files.from(project.fileTree("externalAnnotations"))
}
}
}
val generateAtLexer by lexer("AtLexer", "com/demonwav/mcdev/platform/mcp/at/gen")
val generateAtParser by parser("AtParser", "com/demonwav/mcdev/platform/mcp/at/gen")
val generateAwLexer by lexer("AwLexer", "com/demonwav/mcdev/platform/mcp/aw/gen")
val generateAwParser by parser("AwParser", "com/demonwav/mcdev/platform/mcp/aw/gen")
val generateNbttLexer by lexer("NbttLexer", "com/demonwav/mcdev/nbt/lang/gen")
val generateNbttParser by parser("NbttParser", "com/demonwav/mcdev/nbt/lang/gen")
val generateLangLexer by lexer("LangLexer", "com/demonwav/mcdev/translations/lang/gen")
val generateLangParser by parser("LangParser", "com/demonwav/mcdev/translations/lang/gen")
val generateMEExpressionLexer by lexer("MEExpressionLexer", "com/demonwav/mcdev/platform/mixin/expression/gen")
val generateMEExpressionParser by parser("MEExpressionParser", "com/demonwav/mcdev/platform/mixin/expression/gen")
val generateTranslationTemplateLexer by lexer(
"TranslationTemplateLexer",
"com/demonwav/mcdev/translations/template/gen"
)
val generate by tasks.registering {
group = "minecraft"
description = "Generates sources needed to compile the plugin."
outputs.dir(layout.buildDirectory.dir("gen"))
dependsOn(
generateAtLexer,
generateAtParser,
generateAwLexer,
generateAwParser,
generateNbttLexer,
generateNbttParser,
generateLangLexer,
generateLangParser,
generateMEExpressionLexer,
generateMEExpressionParser,
generateTranslationTemplateLexer,
)
}
sourceSets.main { java.srcDir(generate) }
// Remove gen directory on clean
tasks.clean { delete(generate) }
tasks.withType<PrepareSandboxTask> {
pluginJar.set(tasks.jar.get().archiveFile)
val pluginDirName = intellijPlatform.projectName.get()
from(externalAnnotationsJar) {
into("$pluginDirName/lib/resources")
}
from("templates") {
exclude(".git")
into("$pluginDirName/lib/resources/builtin-templates")
}
}
tasks.runIde {
maxHeapSize = "4G"
System.getProperty("debug")?.let {
systemProperty("idea.ProcessCanceledException", "disabled")
systemProperty("idea.debug.mode", "true")
}
// Kotlin K2 is enabled by default, uncomment to switch to K1
// jvmArgumentProviders += CommandLineArgumentProvider {
// listOf("-Didea.kotlin.plugin.use.k2=false")
// }
// Set these properties to test different languages
// systemProperty("user.language", "fr")
// systemProperty("user.country", "FR")
}