-
-
Notifications
You must be signed in to change notification settings - Fork 76
/
build.gradle
369 lines (304 loc) · 10.3 KB
/
build.gradle
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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
import org.gradle.api.internal.file.FileOperations
import org.quiltmc.launchermeta.version.v1.Library
import org.quiltmc.launchermeta.version.v1.Version
import quilt.internal.constants.Classifiers
import quilt.internal.constants.Constants
import quilt.internal.task.setup.DownloadWantedVersionManifestTask
import quilt.internal.util.serializable.VersionParser
import java.util.stream.Collectors
import java.util.stream.Stream
import static org.gradle.api.plugins.JavaPlugin.JAVADOC_TASK_NAME
import static quilt.internal.task.setup.DownloadWantedVersionManifestTask.DOWNLOAD_WANTED_VERSION_MANIFEST_TASK_NAME
plugins {
id 'maven-publish'
id 'quilt-mappings'
alias libs.plugins.licenser
}
// put these in fields so we don't have to worry about inadvertently accessing the project during task execution
final FileOperations FILE_OPERATIONS = project.fileOperations
final ProviderFactory PROVIDERS = project.providers
final ObjectFactory OBJECTS = project.objects
final USE_SNAPSHOT_HASHES = false
final ENV = System.getenv()
final MINECRAFT_VERSION = libs.versions.minecraft.get()
version = "${MINECRAFT_VERSION}+build.${ENV.getOrDefault('BUILD_NUMBER', 'local')}"
if (ENV.BRANCH_NAME) {
def branch = ENV.BRANCH_NAME.substring(ENV.BRANCH_NAME.lastIndexOf('/') + 1)
if (MINECRAFT_VERSION != branch) {
throw new IllegalStateException("Branch name (${branch}) does not match the mc version (${MINECRAFT_VERSION})")
}
}
sourceSets {
// for constantsJar and sourcesJar input
constants
// package info files, for javadoc input
packageDocs
// for javadoc input
doclet
}
repositories {
ivy {
// hack to download file from url
url = 'https://raw.githubusercontent.com'
patternLayout {
artifact '/[organisation]/[module]/[revision]/allowed_english_words.txt'
}
metadataSources { artifact() }
}
maven {
name 'Mojang'
url 'https://libraries.minecraft.net/'
}
mavenCentral()
maven {
name 'Quilt Repository'
url 'https://maven.quiltmc.org/repository/release'
}
maven {
name 'Fabric Repository'
url 'https://maven.fabricmc.net'
}
maven {
name 'Quilt Snapshot Repository'
url 'https://maven.quiltmc.org/repository/snapshot'
}
mavenLocal()
}
configurations {
dictionary
}
dependencies {
dictionary libs.dictionary
javadocClasspath(libs.quilt.loader)
javadocClasspath(libs.jetbrains.annotations)
// for some other jsr annotations
javadocClasspath(libs.jsr305)
hashed "org.quiltmc:hashed:${MINECRAFT_VERSION}${USE_SNAPSHOT_HASHES ? "-SNAPSHOT" : ""}"
intermediary "net.fabricmc:intermediary:${MINECRAFT_VERSION}:v2"
}
quiltMappings {
minecraftVersion = MINECRAFT_VERSION
mappingsVersion = project.version.toString()
mappingsDir = file('mappings/')
enigmaProfileConfig = file('enigma/enigma_profile.json')
unpickMeta = file('unpick/unpick.json')
}
tasks.combineUnpickDefinitions {
// add project's static unpick definitions
unpickDefinitions.from 'unpick/definitions/'
}
tasks.mappingLint {
dictionaryFile = configurations.dictionary.singleFile
}
tasks.sourcesJar {
sources.from sourceSets.constants.allSource
}
tasks.constantsJar {
constants.from sourceSets.constants.output
}
// Only build jars for package infos if we need to actually expose stuff like annotation in the future.
tasks.build.dependsOn constantsJar, generatePackageInfoMappings,
compressTiny, tinyJar, v2UnmergedMappingsJar, v2MergedMappingsJar
// configure lazily because we get buildDirectory
tasks.named(JAVADOC_TASK_NAME, Javadoc) {
// Needed for javadoc to find the doclet classes.
dependsOn docletClasses
final versionParser = tasks
.named(DOWNLOAD_WANTED_VERSION_MANIFEST_TASK_NAME, DownloadWantedVersionManifestTask)
.flatMap(DownloadWantedVersionManifestTask::provideVersionParser)
final MapProperty<String, String> minecraftLibVersionsByModule = OBJECTS.mapProperty(String, String)
minecraftLibVersionsByModule.set(versionParser
.map(VersionParser::get)
.map(Version::getLibraries)
.map {
it.stream()
.map(Library::getName)
.flatMap { moduleName ->
final delim = ':'
final moduleParts = moduleName.split(delim)
if (moduleParts.length == 3 || moduleParts.length == 4) {
return Stream.of(Map.entry(moduleParts[0] + delim + moduleParts[1], moduleParts[2]))
} else {
logger.error("Unrecognized module format: ${moduleName}")
return Stream.empty()
}
}
.distinct()
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))
}
)
final Closure<Provider<String>> provideModuleVersion = { String module ->
final versionProperty = OBJECTS.property(String)
.convention(PROVIDERS.provider { throw new GradleException("Missing version for module: ${module}") })
versionProperty.set(minecraftLibVersionsByModule.getting(module))
return versionProperty
}
final Closure<Provider<String>> formatVersionedUrl = { String baseUrl, Provider<String> version ->
version.map {"${baseUrl}/${it}/" as String }
}
final gsonUrl = formatVersionedUrl(
'https://javadoc.io/doc/com.google.code.gson/gson',
provideModuleVersion('com.google.code.gson:gson')
)
// use hardcoded version because minecraft depends on a version that doesn't have javadocs
final nettyUrl = formatVersionedUrl(
'https://javadoc.io/doc/io.netty/netty-all',
libs.versions.netty.with.javadoc
)
final commonsCompressUrl = formatVersionedUrl(
'https://javadoc.io/doc/org.apache.commons/commons-compress',
provideModuleVersion('org.apache.commons:commons-compress')
)
final commonsCodecUrl = formatVersionedUrl(
'https://javadoc.io/doc/commons-codec/commons-codec',
provideModuleVersion('commons-codec:commons-codec')
)
[
gsonUrl: gsonUrl,
nettyUrl: nettyUrl,
commonsCompressUrl: commonsCompressUrl,
commonsCodecUrl: commonsCodecUrl
].each(inputs::property)
destinationDir = layout.buildDirectory.get().dir('docs').dir(project.version.toString()).getAsFile()
final docletResources = sourceSets.doclet.resources.asFileTree
// Failing on error is important to ensure that a Javadoc jar is available.
failOnError = true
maxMemory = '2G'
final debug = providers.gradleProperty('quilt.mappings.debug.javadoc')
.map(Boolean::parseBoolean)
.getOrElse(false)
verbose = debug
options {
if (debug) {
verbose()
}
source = '21'
encoding = 'UTF-8'
charSet = 'UTF-8'
memberLevel = JavadocMemberLevel.PRIVATE
splitIndex true
tags(
'apiNote:a:API Note:',
'implSpec:a:Implementation Requirements:',
'implNote:a:Implementation Note:'
)
taglets 'quilt.internal.taglet.MappingTaglet'
// taglet path, header, extra stylesheet settings deferred
it.use()
addBooleanOption '-allow-script-in-comments', true
// https://docs.oracle.com/en/java/javase/21/docs/specs/man/javadoc.html#additional-options-provided-by-the-standard-doclet
addBooleanOption 'Xdoclint:html', true
addBooleanOption 'Xdoclint:syntax', true
addBooleanOption 'Xdoclint:reference', true
addBooleanOption 'Xdoclint:accessibility', true
addStringOption '-notimestamp'
}
source sourceSets.constants.allJava + sourceSets.packageDocs.allJava
doFirst {
// lazy setting
options {
links(
"https://javadoc.io/doc/com.google.guava/guava/${libs.versions.guava.get()}/",
gsonUrl.get(),
"https://javadoc.io/doc/org.jetbrains/annotations/${libs.versions.jetbrains.annotations.get()}/",
"https://javadoc.io/doc/com.google.code.findbugs/jsr305/${libs.versions.jsr305.get()}/",
commonsCompressUrl.get(),
nettyUrl.get(),
'https://javadoc.lwjgl.org/',
'https://logging.apache.org/log4j/2.x/javadoc/log4j-api/',
'https://fastutil.di.unimi.it/docs/',
'https://commons.apache.org/proper/commons-logging/javadocs/api-release/',
'https://commons.apache.org/proper/commons-lang/javadocs/api-release/',
'https://commons.apache.org/proper/commons-io/apidocs/',
commonsCodecUrl.get(),
"https://javadoc.quiltmc.org/quilt-loader/${libs.versions.quilt.loader.get()}/",
"https://docs.oracle.com/en/java/javase/${project.java}/docs/api/"
)
tagletPath sourceSets.doclet.output.classesDirs.files.toList()
header docletResources.filter { it.name == 'javadoc_header.txt' }.singleFile.text.trim()
addFileOption '-add-stylesheet', docletResources.filter { it.name == 'style.css' }.singleFile
}
}
doLast {
FILE_OPERATIONS.copy {
it.from docletResources
it.include 'copy_on_click.js'
it.into destinationDir
}
}
}
java {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}
tasks.withType(JavaCompile).configureEach {
it.options.encoding = 'UTF-8'
it.options.release = 21
}
license {
header file('HEADER')
include '**/*.java'
}
publishing {
publications {
maven(MavenPublication) {
groupId 'org.quiltmc'
artifactId Constants.MAPPINGS_NAME
version project.version
// quilt-mappings-<version>-tiny.gz
compressTiny.artifact maven
// quilt-mappings-<version>.jar
artifact tinyJar
// quilt-mappings-<version>-v2.jar
artifact v2UnmergedMappingsJar
// quilt-mappings-<version>-mergedv2.jar
artifact v2MergedMappingsJar
// quilt-mappings-<version>-constants.jar
artifact constantsJar
// quilt-mappings-<version>-sources.jar
artifact sourcesJar
// quilt-mappings-<version>-javadoc.jar
artifact javadocJar
// See below the publishing block for intermediary artifact publishing
}
}
repositories {
if (ENV.MAVEN_URL) {
maven {
url ENV.MAVEN_URL
credentials {
username ENV.MAVEN_USERNAME
password ENV.MAVEN_PASSWORD
}
}
} else if (USE_SNAPSHOT_HASHES && ENV.SNAPSHOTS_URL) {
maven {
url = ENV.SNAPSHOTS_URL
credentials {
username = ENV.SNAPSHOTS_USERNAME
password = ENV.SNAPSHOTS_PASSWORD
}
}
}
mavenLocal()
}
}
tasks.withType(AbstractPublishToMaven).configureEach {
// Won't run if mapIntermediary.intermediaryFile is absent
dependsOn buildIntermediary
doFirst {
if (mapIntermediary.intermediaryFile.isPresent()) {
final addArtifact = { Task task, String artifactClassifier ->
if (publication.artifacts.findAll { it.classifier == artifactClassifier }.isEmpty()) {
publication.artifact(task) {
classifier artifactClassifier
}
}
}
// quilt-mappings-<version>-intermediary-v2.jar
addArtifact(intermediaryV2MappingsJar, Classifiers.INTERMEDIARY_V2)
// quilt-mappings-<version>-intermediary-mergedv2.jar
addArtifact(intermediaryV2MergedMappingsJar, Classifiers.INTERMEDIARY_V2_MERGED)
}
}
}