forked from FabricMC/fabric-loader
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.gradle
305 lines (261 loc) · 8.36 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
plugins {
id 'java'
id 'idea'
id 'eclipse'
id 'maven-publish'
id("org.cadixdev.licenser") version "0.5.0"
//id("fabric-loom") version "0.2.6-SNAPSHOT"
}
task wrapper(type: Wrapper) {
gradleVersion = '4.9'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
archivesBaseName = "cursed-fabric-loader"
// Fetch build number from Jenkins
def ENV = System.getenv()
//version = version + (ENV.GITHUB_ACTIONS ? "" : "+local")
repositories {
mavenCentral()
jcenter()
maven {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
}
maven {
name = 'mojang'
url = 'https://libraries.minecraft.net/'
}
}
configurations {
installed
launchwrapper.extendsFrom installed
implementation.extendsFrom(installed, launchwrapper)
testCompileOnly.extendsFrom compileOnly
}
dependencies {
//minecraft "com.mojang:minecraft:1.14.4"
//mappings "net.fabricmc:yarn:1.14.4+build.1"
installed group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.8.1'
installed group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.8.1'
installed group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
installed group: 'com.google.guava', name: 'guava', version: '21.0'
// Minecraft's JAR uses these annotations
compileOnly 'com.google.code.findbugs:jsr305:3.0.2'
// fabric-loader dependencies
annotationProcessor installed ("org.ow2.asm:asm:${project.asm_version}")
annotationProcessor installed ("org.ow2.asm:asm-analysis:${project.asm_version}")
annotationProcessor installed ("org.ow2.asm:asm-commons:${project.asm_version}")
annotationProcessor installed ("org.ow2.asm:asm-tree:${project.asm_version}")
annotationProcessor installed ("org.ow2.asm:asm-util:${project.asm_version}")
installed('net.fabricmc:sponge-mixin:0.9.2+mixin.0.8.2') {
exclude module: 'launchwrapper'
exclude module: 'guava'
}
installed 'net.fabricmc:tiny-mappings-parser:0.2.2.14'
installed 'net.fabricmc:tiny-remapper:0.3.0.70'
installed 'net.fabricmc:access-widener:1.0.0'
installed 'com.google.jimfs:jimfs:1.2-fabric'
installed 'net.fabricmc:fabric-loader-sat4j:2.3.5.4'
// launchwrapper + dependencies
launchwrapper ('net.minecraft:launchwrapper:1.12') {
transitive = false
}
launchwrapper 'net.sf.jopt-simple:jopt-simple:5.0.3'
testCompileOnly 'org.jetbrains:annotations:19.0.0'
// Unit testing for mod metadata
testImplementation('org.junit.jupiter:junit-jupiter:5.6.2')
}
processResources {
inputs.property "version", project.version
filesMatching("fabric.mod.json") {
expand "version": project.version
}
}
import groovy.json.JsonBuilder
String generalInstallerJSON(Configuration config, Closure extra) {
def json = new JsonBuilder()
def emptyList = [] //Groovy makes json([]) ambiguous so we take the clear route
json {
version 1
libraries {
client emptyList
common json(config.allDependencies.findAll {
it instanceof ExternalDependency
}) {dependency ->
def repo = ['https://libraries.minecraft.net', 'https://maven.fabricmc.net', 'https://maven.minecraftforge.net'].find {repo ->
def url = "$repo/${dependency.group.replace('.', '/')}/${dependency.name}/${dependency.version}/${dependency.name}-${dependency.version}.jar".toURL()
def connection = url.openConnection()
connection.requestMethod = 'HEAD'
def back = connection.responseCode
connection.disconnect()
if ((200..<300).contains(back)) {
//println "$repo has ${dependency.group}:${dependency.name}:${dependency.version}"
return repo
} else {
//println "$repo lacks ${dependency.group}:${dependency.name}:${dependency.version}"
return null
}
}
if (repo == null) throw new IllegalArgumentException("Can't find repository for ${dependency.group}:${dependency.name}:${dependency.version}")
name "${dependency.group}:${dependency.name}:${dependency.version}"
url "$repo/" //The trailing slash is probably optional
}
server emptyList
}
extra(delegate)
}
return json.toPrettyString()
}
task createInstallerJSON() {
def output = file("$buildDir/generated-resources/fabric-installer.json")
outputs.file(output)
doLast {
output.withWriter('utf-8') {writer ->
writer.write(generalInstallerJSON(configurations.installed) {json ->
json.mainClass {
client 'net.fabricmc.loader.launch.knot.KnotClient'
server 'net.fabricmc.loader.launch.knot.KnotServer'
}
})
}
}
}
task createInstallerLWJSON() {
def output = file("$buildDir/generated-resources/fabric-installer.launchwrapper.json")
outputs.file(output)
doLast {
output.withWriter('utf-8') {writer ->
writer.write(generalInstallerJSON(configurations.launchwrapper) {json ->
def emptyList = []
json.mainClass 'net.minecraft.launchwrapper.Launch'
json.arguments {
client emptyList
common emptyList
server emptyList
}
json.launchwrapper {
client json(['net.fabricmc.loader.launch.FabricClientTweaker'])
common emptyList
server json(['net.fabricmc.loader.launch.FabricServerTweaker'])
}
})
}
}
}
jar {
from createInstallerJSON.outputs
from createInstallerLWJSON.outputs
manifest {
attributes (
'Main-Class': 'net.fabricmc.loader.launch.server.FabricServerLauncher'
)
}
from("LICENSE") {
rename { "${it}_${project.archivesBaseName}"}
}
}
task copyJson(type: Copy, dependsOn: createInstallerJSON) {
from(createInstallerJSON.outputs) {
rename { "${archivesBaseName}-${version}.json" }
}
into 'build/libs'
}
task copyJsonLw(type: Copy, dependsOn: createInstallerLWJSON) {
from(createInstallerLWJSON.outputs) {
rename { "${archivesBaseName}-${version}.launchwrapper.json" }
}
into 'build/libs'
}
task installerJar(type: Jar) {
from createInstallerJSON.outputs
classifier 'installer'
}
build.dependsOn copyJson, copyJsonLw, installerJar
tasks.withType(JavaCompile).configureEach {
it.options.encoding = "UTF-8"
// The Minecraft launcher currently installs Java 8 for users, so your mod probably wants to target Java 8 too
// JDK 9 introduced a new way of specifying this that will make sure no newer classes or methods are used.
// We'll use that if it's available, but otherwise we'll use the older option.
if (JavaVersion.current().isJava9Compatible()) {
//it.options.release = 8
}
}
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this task, sources will not be generated.
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
javadoc {
options {
if (file("README.html").exists()) {
overview = "README.html"
}
source = "8"
encoding = 'UTF-8'
charSet = 'UTF-8'
memberLevel = JavadocMemberLevel.PACKAGE
links(
'https://asm.ow2.io/javadoc/',
'https://docs.oracle.com/javase/8/docs/api/',
'https://logging.apache.org/log4j/2.x/log4j-api/apidocs/'
)
// Disable the crazy super-strict doclint tool in Java 8
addStringOption('Xdoclint:none', '-quiet')
}
source sourceSets.main.allJava.srcDirs
classpath = sourceSets.main.compileClasspath + sourceSets.main.output // compile impl stuff for dep as well
include("**/api/**")
// workaround as one of the api stuff use that package
failOnError false
}
task javadocJar(type: Jar) {
dependsOn javadoc
from javadoc.destinationDir
classifier = 'javadoc'
}
build.dependsOn javadocJar
license {
header file("HEADER")
include '**/*.java'
// Exclude gson since it is google's code, we just modify and bundle it
exclude '**/lib/gson/*.java'
exclude '**/io/github/minecraftcursedlegacy/**'
}
publishing {
publications {
mavenJava(MavenPublication) {
// add all the jars that should be included when publishing to maven
artifact(jar) {
builtBy jar
}
artifact(sourcesJar) {
builtBy sourcesJar
}
artifact javadocJar
artifact installerJar
artifact(createInstallerJSON.outputs.files.singleFile) {
builtBy copyJson
}
artifact(createInstallerLWJSON.outputs.files.singleFile) {
builtBy copyJsonLw
classifier = "launchwrapper"
}
}
}
// select the repositories you want to publish to
repositories {
maven {
def mavenUrl = project.hasProperty('maven_url') ? project.property('maven_url') : ""
url mavenUrl
if(mavenUrl.startsWith("http")) {
credentials {
username project.hasProperty('maven_username') ? project.property('maven_username') : ""
password project.hasProperty('maven_password') ? project.property('maven_password') : ""
}
}
}
}
}