-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlegacy-fabric-api.gradle
427 lines (361 loc) · 11.5 KB
/
legacy-fabric-api.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
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
buildscript {
repositories {
gradlePluginPortal()
maven {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
}
mavenLocal()
}
dependencies {
classpath 'org.kohsuke:github-api:1.135'
classpath "org.ajoberstar.grgit:grgit-gradle:3.1.1"
classpath "gradle.plugin.com.matthewprenger:CurseGradle:1.4.0"
classpath "gradle.plugin.org.cadixdev.gradle:licenser:0.6.1"
classpath "net.fabricmc:fabric-loom:0.12.27"
}
}
apply plugin: org.gradle.api.plugins.JavaLibraryPlugin
apply plugin: org.gradle.plugins.ide.eclipse.EclipsePlugin
apply plugin: org.gradle.plugins.ide.idea.IdeaPlugin
apply plugin: org.gradle.api.publish.maven.plugins.MavenPublishPlugin
apply plugin: net.fabricmc.loom.bootstrap.LoomGradlePluginBootstrap
apply plugin: org.cadixdev.gradle.licenser.Licenser
apply plugin: org.ajoberstar.grgit.gradle.GrgitPlugin
apply plugin: com.matthewprenger.cursegradle.CurseGradlePlugin
apply plugin: org.gradle.plugins.signing.SigningPlugin
def ENV = System.getenv()
setVersion("${project.base_version}+${project.mc_version}")
logger.lifecycle("Building Fabric: " + version)
import org.apache.commons.codec.digest.DigestUtils
def getSubprojectVersion(project, version) {
if (grgit == null) {
return version + "+nogit"
}
def latestCommits = grgit.log(paths: [rootProject.projectDir.toPath().relativize(project.projectDir.toPath()).toString()], maxCommits: 1)
if (latestCommits.isEmpty()) {
return version + "+uncommited"
} else {
return version + "+" + latestCommits.get(0).id.substring(0, 8) +
DigestUtils.sha256Hex("${project.mc_version}").substring(0, 2)
}
}
def getBranch() {
if (System.getenv().GIT_BRANCH) {
def branch = System.getenv().GIT_BRANCH
return branch.substring(branch.lastIndexOf("/") + 1)
}
if (grgit == null) {
return "unknown"
}
def branch = grgit.branch.current().name
return branch.substring(branch.lastIndexOf("/") + 1)
}
def static setupRepositories(RepositoryHandler repositories) {
def ENV = System.getenv()
if (ENV.MAVEN_PUBLISH_TOKEN) {
repositories.maven {
url 'https://maven.legacyfabric.net/'
credentials {
username 'legacyfabric-ci'
password ENV.MAVEN_PUBLISH_TOKEN
}
authentication {
basic(BasicAuthentication)
}
}
}
}
def moduleDependencies(project, List<String> depNames) {
def deps = depNames.iterator().collect { project.dependencies.project(path: ":$it", configuration: 'namedElements') }
project.dependencies {
deps.each {
api it
}
}
if (project.name != "legacy-fabric-logger-api-v1") {
deps.add(project.dependencies.project(path: ":legacy-fabric-logger-api-v1", configuration: 'namedElements'));
}
// As we manually handle the maven artifacts, we need to also manually specify the deps.
project.publishing {
publications {
mavenJava(MavenPublication) {
pom.withXml {
def depsNode = asNode().appendNode("dependencies")
deps.each {
def depNode = depsNode.appendNode("dependency")
depNode.appendNode("groupId", it.group)
depNode.appendNode("artifactId", it.name)
depNode.appendNode("version", it.version)
depNode.appendNode("scope", "compile")
}
}
}
}
}
}
allprojects {
apply plugin: org.gradle.api.plugins.JavaLibraryPlugin
apply plugin: org.gradle.api.plugins.quality.CheckstylePlugin
apply plugin: org.gradle.api.publish.maven.plugins.MavenPublishPlugin
apply plugin: org.gradle.plugins.signing.SigningPlugin
apply plugin: net.fabricmc.loom.bootstrap.LoomGradlePluginBootstrap
apply plugin: org.cadixdev.gradle.licenser.Licenser
sourceCompatibility = 1.8
targetCompatibility = 1.8
group = "net.legacyfabric.legacy-fabric-api"
sourceSets {
testmod {
compileClasspath += main.compileClasspath
runtimeClasspath += main.runtimeClasspath
}
}
publishing {
setupRepositories(repositories)
}
repositories {
maven { url "https://maven.legacyfabric.net/" }
}
loom {
runtimeOnlyLog4j = true
runs {
testmodClient {
client()
ideConfigGenerated project.rootProject == project
name = "Testmod Client"
source sourceSets.testmod
vmArgs "-Dmixin.debug.export=true"
}
testmodServer {
server()
ideConfigGenerated project.rootProject == project
name = "Testmod Server"
source sourceSets.testmod
vmArgs "-Dmixin.debug.export=true"
}
}
shareRemapCaches = true
setIntermediaryUrl('https://maven.legacyfabric.net/net/fabricmc/intermediary/%1$s/intermediary-%1$s-v2.jar');
}
dependencies {
minecraft("com.mojang:minecraft:${project.mc_version}")
mappings("net.fabricmc:yarn:${project.mc_version}+build.${project.yarn_version}:v2")
modApi("net.fabricmc:fabric-loader:${project.loader_version}")
implementation 'com.mojang:brigadier:1.0.17'
if (System.getProperty("os.name").toLowerCase().contains("mac")) {
implementation 'org.lwjgl.lwjgl:lwjgl_util:2.9.4-nightly-20150209'
implementation 'org.lwjgl.lwjgl:lwjgl:2.9.4-nightly-20150209'
implementation 'org.lwjgl.lwjgl:lwjgl-platform:2.9.4-nightly-20150209'
}
}
if (System.getProperty("os.name").toLowerCase().contains("mac")) {
configurations.all {
resolutionStrategy {
dependencySubstitution {
substitute module('org.lwjgl.lwjgl:lwjgl_util:2.9.2-nightly-201408222') with module('org.lwjgl.lwjgl:lwjgl_util:2.9.4-nightly-20150209')
substitute module('org.lwjgl.lwjgl:lwjgl:2.9.2-nightly-201408222') with module('org.lwjgl.lwjgl:lwjgl:2.9.4-nightly-20150209')
}
force 'org.lwjgl.lwjgl:lwjgl-platform:2.9.4-nightly-20150209'
}
}
}
processResources {
inputs.property "version", project.version
filesMatching("fabric.mod.json") {
expand "version": project.version
}
}
license {
header rootProject.file('HEADER')
include '**/*.java'
exclude '**/lib/sponge/*.java'
exclude '**/lib/sponge/**/*.java'
}
java {
withSourcesJar()
}
checkstyle {
configFile = rootProject.file("checkstyle.xml")
toolVersion = "9.1"
}
tasks.withType(AbstractArchiveTask) {
preserveFileTimestamps = false
reproducibleFileOrder = true
}
tasks.withType(GenerateModuleMetadata) {
enabled = false
}
}
javadoc {
options {
source = "8"
encoding = 'UTF-8'
charSet = 'UTF-8'
memberLevel = JavadocMemberLevel.PACKAGE
links(
'https://guava.dev/releases/21.0/api/docs/',
'https://asm.ow2.io/javadoc/',
'https://docs.oracle.com/javase/8/docs/api/',
'https://jenkins.liteloader.com/job/Mixin/javadoc/',
'https://logging.apache.org/log4j/2.x/log4j-api/apidocs/'
// Need to add minecraft jd publication etc once there is one available
)
// Disable the crazy super-strict doclint tool in Java 8
addStringOption('Xdoclint:none', '-quiet')
}
allprojects.each {
source(it.sourceSets.main.allJava.srcDirs)
}
classpath = sourceSets.main.compileClasspath
include("**/api/**")
failOnError false
}
task javadocJar(type: Jar) {
dependsOn javadoc
from javadoc.destinationDir
//Set as `fatjavadoc` to prevent an ide form trying to use this javadoc, over using the modules javadoc
archiveClassifier = "fatjavadoc"
}
build.dependsOn javadocJar
subprojects {
dependencies {
testmodImplementation sourceSets.main.output
if (project.name != "legacy-fabric-resource-loader-v1") {
testmodImplementation project(path: ':legacy-fabric-resource-loader-v1', configuration: 'namedElements')
}
if (findProject(':legacy-fabric-registry-sync-api-v1') != null && project.name != "legacy-fabric-registry-sync-api-v1") {
testmodRuntimeOnly project(path: ':legacy-fabric-registry-sync-api-v1', configuration: 'namedElements')
}
if (project.name != "legacy-fabric-logger-api-v1") {
api project(path: ":legacy-fabric-logger-api-v1", configuration: 'namedElements')
}
}
publishing {
publications {
mavenJava(MavenPublication) {
artifact(remapJar) {
builtBy(remapJar)
}
artifact(remapSourcesJar) {
builtBy remapSourcesJar
}
}
}
}
// We manually handle the pom generation
loom.disableDeprecatedPomGeneration(publishing.publications.mavenJava)
javadoc.enabled = false
afterEvaluate {
// Disable the gen sources task on sub projects
genSourcesWithFernFlower.enabled = false
genSourcesWithCfr.enabled = false
}
}
task remapMavenJar(type: net.fabricmc.loom.task.RemapJarTask, dependsOn: jar) {
input = jar.archiveFile
archiveFileName = "${archivesBaseName}-${project.version}-maven.jar"
addNestedDependencies = false
}
build.dependsOn remapMavenJar
publishing {
publications {
mavenJava(MavenPublication) {
artifact(remapMavenJar) {
builtBy remapMavenJar
}
artifact(sourcesJar) {
builtBy remapSourcesJar
}
artifact javadocJar
pom.withXml {
def depsNode = asNode().appendNode("dependencies")
subprojects.each {
def depNode = depsNode.appendNode("dependency")
depNode.appendNode("groupId", it.group)
depNode.appendNode("artifactId", it.name)
depNode.appendNode("version", it.version)
depNode.appendNode("scope", "compile")
}
}
}
}
}
// Required until the deprecation is removed. Fabric API's main jar that is published to maven does not contain sub modules.
loom.disableDeprecatedPomGeneration(publishing.publications.mavenJava)
task licenseFormatAll
subprojects { p -> licenseFormatAll.dependsOn("${p.path}:licenseFormat") }
subprojects.each { remapJar.dependsOn("${it.path}:remapJar") }
sourceSets {
testmod
}
dependencies {
afterEvaluate {
subprojects.each {
api project(path: ":${it.name}", configuration: "namedElements")
testmodImplementation project("${it.name}:").sourceSets.testmod.output
}
}
}
remapJar {
afterEvaluate {
subprojects.each {
// Include the signed or none signed jar from the sub project.
nestedJars.from project("${it.name}:").tasks.getByName("remapJar")
}
}
}
curseforge {
if (project.hasProperty('curse_api_key')) {
apiKey = project.getProperty('curse_api_key')
} else if (ENV.CURSE_API_KEY) {
apiKey = ENV.CURSE_API_KEY
}
project {
id = '400281'
changelog = 'A changelog can be found at https://github.com/Legacy-Fabric/fabric/commits'
releaseType = 'beta'
addGameVersion "${project.mc_version}"
addGameVersion 'Fabric'
mainArtifact(remapJar) {
displayName = "[${project.mc_version}] Legacy Fabric API ${project.base_version}"
}
afterEvaluate {
uploadTask.dependsOn("remapJar")
}
}
options {
forgeGradleIntegration = false
}
}
import org.kohsuke.github.GHReleaseBuilder
import org.kohsuke.github.GitHub
task github(dependsOn: remapJar) {
onlyIf {
ENV.GITHUB_TOKEN
}
doLast {
def github = GitHub.connectUsingOAuth(ENV.GITHUB_TOKEN as String)
def repository = github.getRepository(ENV.GITHUB_REPOSITORY)
def releaseBuilder = new GHReleaseBuilder(repository, version as String)
releaseBuilder.name("[$project.minecraft_version] Legacy Fabric API $project.version")
releaseBuilder.body(ENV.CHANGELOG ?: "No changelog provided")
releaseBuilder.commitish(getBranch())
releaseBuilder.prerelease(false)
def ghRelease = releaseBuilder.create()
ghRelease.uploadAsset(remapJar.archiveFile.get().getAsFile(), "application/java-archive");
}
}
// A task to ensure that the version being released has not already been released.
task checkVersion {
doFirst {
def xml = new URL("https://maven.legacyfabric.net/net/legacyfabric/legacy-fabric-api/legacy-fabric-api/maven-metadata.xml").text
def metadata = new XmlSlurper().parseText(xml)
def versions = metadata.versioning.versions.version*.text();
if (versions.contains(version)) {
throw new RuntimeException("${version} has already been released!")
}
}
}
github.mustRunAfter checkVersion
publish.mustRunAfter checkVersion
project.tasks.curseforge.mustRunAfter checkVersion