forked from xa/RetroWrapper
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.gradle
306 lines (251 loc) · 9.48 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
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.guardsquare:proguard-gradle:7.5.0'
}
}
plugins {
id 'java-library'
id 'maven-publish'
id 'io.github.goooler.shadow' version '8.1.7'
//id 'checkstyle' // TODO: This is a reminder for me to setup checkstyle.
}
import org.apache.tools.ant.filters.ReplaceTokens
// Reproducible builds! https://docs.gradle.org/4.9/userguide/working_with_files.html#sec:reproducible_archives
tasks.withType(AbstractArchiveTask).configureEach {
preserveFileTimestamps = false
reproducibleFileOrder = true
}
apply plugin: 'java'
// TODO: This is a reminder for me to setup checkstyle.
/* apply plugin: 'checkstyle'
configurations {
checkstyleConfig
}
def versions = [
checkstyle: '6.2',
]
dependencies {
checkstyleConfig ("com.puppycrawl.tools:checkstyle:${versions.checkstyle}") {
transitive = false
}
}
checkstyle {
toolVersion = "${versions.checkstyle}"
config = resources.text.fromArchiveEntry(configurations.checkstyleConfig, 'google_checks.xml')
} */
final def compiler = javaToolchains.compilerFor {
languageVersion = JavaLanguageVersion.of(7)
}
// Tells Gradle to use the previously defined Java 7 compatible JDK.
java {
sourceCompatibility = 1.5
targetCompatibility = 1.5
toolchain {
compiler
}
}
// Tells Gradle to always compile with the previously defined Java 7 compatible JDK.
tasks.withType(JavaCompile).configureEach {
javaCompiler = compiler
sourceCompatibility = 1.5
targetCompatibility = 1.5
// Tells Gradle to include more debug information in compiled .class files.
options.debug = true
options.debugOptions.debugLevel = 'source,lines,vars'
}
repositories {
mavenCentral()
maven {
name = 'mojang'
url = 'https://libraries.minecraft.net/'
}
}
shadowJar {
from 'LICENSE.md'
dependencies {
exclude(dependency("org.ow2.asm:asm-all:${project.asmVersion}"))
exclude(dependency("net.minecraft:launchwrapper:${project.launchwrapperVersion}"))
//exclude(dependency("net.sf.jopt-simple:jopt-simple:${project.joptSimpleVersion}"))
exclude(dependency("org.lwjgl.lwjgl:lwjgl:${project.lwjglVersion}"))
}
minimize()
// Hacky exclusions to minimise file size.
exclude 'org/**/*.txt'
exclude 'META-INF/maven/**/*.*'
exclude 'templates/release-notes.vm'
// Currently, this merges all licences from each library into one file, as well as the same for notices.
// TODO: Come up with a better way to do this. Ideally I'd rename the file based on the library.
//append 'META-INF/LICENSE.txt'
exclude 'META-INF/LICENSE.txt'
from 'COMMONS-LICENSE.txt'
from 'MINIMAL-JSON-LICENSE.txt'
append 'META-INF/NOTICE.txt'
// Relocate libraries to prevent them from leaking into the classpath for other applications
relocate 'org.apache.commons.codec', 'com.zero.retrowrapper.shadow.commons-codec'
relocate 'org.apache.commons.io', 'com.zero.retrowrapper.shadow.commons-io'
relocate 'org.apache.commons.lang3', 'com.zero.retrowrapper.shadow.commons-lang3'
relocate 'com.eclipsesource.json', 'com.zero.retrowrapper.shadow.minimal-json'
archiveClassifier = 'debug'
}
version = project.version
def versionWithMetadata = version
def gitTag
task checkRelease {
if (System.getenv('BUILD_RELEASE') != 'true') {
version += '-SNAPSHOT'
gitTag = 'git rev-parse --short HEAD'.execute().text.trim()
versionWithMetadata = version + '+' + gitTag
if (!System.getenv('CI')) {
versionWithMetadata += '.local'
}
} else {
gitTag = System.getenv('RELEASE_TAG')
}
}
dependencies {
// asm
api "org.ow2.asm:asm-all:${project.asmVersion}"
// launchwrapper + dependencies
api("net.minecraft:launchwrapper:${project.launchwrapperVersion}") {
transitive = false
}
// jopt
//api "net.sf.jopt-simple:jopt-simple:${project.joptSimpleVersion}"
// lwjgl
api("org.lwjgl.lwjgl:lwjgl:${project.lwjglVersion}") {
transitive = false
}
// commons-codec, for Base 64 decoding of skin strings
implementation "commons-codec:commons-codec:${project.commonsCodecVersion}"
// commons-io, for file access
implementation "commons-io:commons-io:${project.commonsIOVersion}"
// commons-lang, for OS utilities
implementation "org.apache.commons:commons-lang3:${project.commonsLangVersion}"
// minimal-json
implementation "com.eclipsesource.minimal-json:minimal-json:${project.minimalJsonVersion}"
}
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
processResources {
inputs.property 'version', project.version // Redo this task when version value changes.
inputs.property 'versionWithMetadata', versionWithMetadata
inputs.property 'gitTag', gitTag
filesMatching('com/zero/retrowrapper/retrowrapperVersion.txt') {
// replace build variables
expand 'version': versionWithMetadata, 'tag': gitTag
}
// Minify .json files in built .jar
doLast {
fileTree(dir: outputs.files.asPath, includes: [
"**/*.json"
]).each { final File file ->
file.text = JsonOutput.toJson(new JsonSlurper().parse(file))
}
}
}
// Ensures that the encoding of source files is set to UTF-8, see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
}
configurations {
//depsForProGuard.extendsFrom(implementation, api)
depsForProGuard.extendsFrom(api)
}
// This task uses ProGuard to shrink the built .jar's file size and optimise the bytecode, mainly by removing unused shadowed dependencies.
tasks.register('proguard', proguard.gradle.ProGuardTask) {
dependsOn(shadowJar)
injars 'build/libs/' + rootProject.name + '-' + version + '-debug.jar'
outjars 'build/libs/' + rootProject.name + '-' + version + '.jar'
// Get the location of rt.jar from the provided toolchain.
// Note to self: probably support building with not outdated versions of Java in the future.
libraryjars compiler.get().metadata.installationPath.asFile.absolutePath + '/lib/rt.jar'
// If rt.jar is not there, try looking inside a JRE folder instead.
libraryjars compiler.get().metadata.installationPath.asFile.absolutePath + '/jre/lib/rt.jar'
// Add relevant libraries to ProGuard's list of libraries to optimise against.
libraryjars project.configurations.depsForProGuard
// Run more optimisation passes on release
if (System.getenv('BUILD_RELEASE') == 'true') {
optimizationpasses 99
}
// The rest of the configs are in this file
configuration 'guard.pro'
}
jar {
manifest {
attributes(
'Main-Class': 'com.zero.retrowrapper.installer.Installer'
)
}
enabled = false
dependsOn(proguard)
}
// This task creates a .jar file containing the source code of this project.
tasks.register('sourcesJar', Jar) {
archiveClassifier = 'sources'
from sourceSets.main.allSource
from 'LICENSE.md'
}
// This task creates a Java 6 - 8 compatible MultiMC instance with the current build of RetroWrapper.
// This instance is intended to have parity with the standard launcher.
tasks.register('createMultiMCInstance', Zip) {
dependsOn(proguard)
inputs.property 'rrVersion', project.version
inputs.property 'versionWithMetadata', versionWithMetadata
archiveFileName = rootProject.name + '-' + project.version + '-MultiMC.J6.zip'
destinationDirectory = layout.buildDirectory.dir('libs')
from('multimc') {
exclude 'patches/RetroWrapper-J9.json'
filesMatching(['mmc-pack.json', 'patches/RetroWrapper-J6.json']) {
filter(ReplaceTokens, tokens: [rrVersion: project.version])
}
rename('RetroWrapper-J6.json', 'RetroWrapper.json')
}
from(proguard.outputs.files.singleFile) {
into 'libraries/'
rename { String libraryName ->
libraryName.replace("RetroWrapper", "retrowrapper")
}
}
}
// This task creates a Java 9+ compatible MultiMC instance with the current build of RetroWrapper.
// This instance uses newer libraries than the standard launcher so LaunchWrapper can run on Java 9+.
tasks.register('createJ9MultiMCInstance', Zip) {
dependsOn(proguard)
inputs.property 'rrVersion', project.version
inputs.property 'versionWithMetadata', versionWithMetadata
archiveFileName = rootProject.name + '-' + project.version + '-MultiMC.J9+.zip'
destinationDirectory = layout.buildDirectory.dir('libs')
from('multimc') {
exclude 'patches/RetroWrapper-J6.json'
filesMatching(['mmc-pack.json', 'patches/RetroWrapper-J9.json']) {
filter(ReplaceTokens, tokens: [rrVersion: project.version])
}
rename('RetroWrapper-J9.json', 'RetroWrapper.json')
}
from(proguard.outputs.files.singleFile) {
into 'libraries/'
rename { String libraryName ->
libraryName.replace("RetroWrapper", "retrowrapper")
}
}
}
build.finalizedBy(createMultiMCInstance, createJ9MultiMCInstance)
artifacts {
archives sourcesJar
}
publishing {
publications {
mavenJava(MavenPublication) {
// Shadowed .jar
final publication ->
project.shadow.component(publication)
// Source code in a .jar
artifact(sourcesJar) {
builtBy sourcesJar
}
}
}
}