-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.gradle
270 lines (231 loc) · 8.4 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
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.time.format.DateTimeFormatter
plugins {
id 'application'
id 'java-library'
id 'maven-publish'
id 'eclipse'
id 'idea'
alias(libs.plugins.shadow)
alias(libs.plugins.licenser)
}
group = "com.mcmoddev"
archivesBaseName = "ReLauncher"
java.toolchain.languageVersion = JavaLanguageVersion.of(21)
sourceSets {
api {}
agent {}
launcher {}
selfupdate {}
}
configurations {
shade
launcherImplementation.extendsFrom(shade)
runtimeElements.extendsFrom(shade) // for the POM
globalCompileOnly
apiCompileOnly.extendsFrom(globalCompileOnly)
agentCompileOnly.extendsFrom(globalCompileOnly)
launcherCompileOnly.extendsFrom(globalCompileOnly)
compileOnly.extendsFrom(globalCompileOnly)
logback
launcherRuntimeOnly.extendsFrom(logback)
}
def agentClass = "com.mcmoddev.relauncher.agent.Agent"
application {
mainClass.set('com.mcmoddev.relauncher.Main')
}
repositories {
mavenCentral()
maven {
url "https://clojars.org/repo/"
}
maven {
name 'jda-chewtils'
url 'https://m2.chew.pro/snapshots'
}
maven { url 'https://jitpack.io' }
}
license {
ignoreFailures = true // Temporarily downgrade license header violations to warnings, because in-flux development
header = file('LicenseHeader.md')
include '**/*.java'
include '**/*.kt'
exclude '**/package-info.java'
exclude '**/module-info.java'
newLine = false
properties {
year = OffsetDateTime.now(ZoneOffset.UTC).withNano(0).getYear()
}
}
dependencies {
implementation sourceSets.api.output
api sourceSets.api.output
agentCompileOnly libs.jda // This is just a compat layer for jda mentionables. DO NOT USE FOR ANYTHING ELSE as the agent will not have it shaded
agentCompileOnly libs.logback
agentImplementation sourceSets.api.output
launcherImplementation sourceSets.main.output
shade sourceSets.api.output
shade libs.gson
shade libs.configurate.hocon
final slf4j = "org.slf4j:slf4j-api:2.0.13"
launcherCompileOnly slf4j
runtimeOnly slf4j
logback(libs.logback) {
exclude module: 'logback-classic'
}
logback slf4j
// Discord stuff
shade libs.jda
shade(libs.chewtils) {
// Exclude unneeded packages without using a specific chewtils module
// to avoid subproject weirdness
exclude module: 'jda-chewtils-menu'
exclude module: 'jda-chewtils-examples'
exclude module: 'jda-chewtils-auth'
}
globalCompileOnly libs.jsr305
globalCompileOnly libs.annotations
}
publishing {
publications {
maven(MavenPublication) {
groupId = group
artifactId = archivesBaseName.toLowerCase(Locale.ROOT)
version = project.version
from components.java
}
}
}
// Relocates all of the tasks from build
tasks.configureEach {
if (it.group == 'build') it.group = 'other'
}
tasks.register('agentJar', Jar).configure {
from sourceSets.api.output
from sourceSets.agent.output
archiveClassifier.set 'agent'
group 'build'
description 'Builds the agent JAR'
final var actualDateTime = OffsetDateTime.now(ZoneOffset.UTC).withNano(0)
final var currentDateTime = DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(actualDateTime)
manifest {
attributes([
'Timestamp' : currentDateTime,
'Specification-Title' : archivesBaseName,
'Specification-Vendor' : 'Minecraft Mod Development',
'Specification-Version' : '1',
'Implementation-Title' : archivesBaseName,
'Implementation-Version' : "${project.version}",
'Implementation-Vendor' : 'Minecraft Mod Development',
'Implementation-Timestamp': currentDateTime,
'Built-On-Java' : "${System.getProperty('java.vm.version')} (${System.getProperty('java.vm.vendor')})",
"Premain-Class" : agentClass,
"Can-Redefine-Classes" : false,
"Can-Retransform-Classes" : false
])
}
}
tasks.register('copyAgentJar', Copy) {
dependsOn 'agentJar'
mustRunAfter(tasks.named('agentJar'))
mustRunAfter(tasks.named('processLauncherResources'))
from "$buildDir/libs/$archivesBaseName-$version-agent.jar"
into "$buildDir/resources/launcher/"
rename "$archivesBaseName-$version-agent.jar", "relauncher-agent.zip"
}
tasks.register('selfUpdateJar', Jar).configure {
from sourceSets.selfupdate.output
archiveClassifier.set 'selfupdate'
group 'build'
description 'Builds the selfupdate JAR'
manifest.attributes(makeManifestAttributes('Main-Class', 'com.mcmoddev.relauncher.selfupdate.SelfUpdate'))
}
tasks.register('copySelfUpdateJar', Copy) {
dependsOn 'selfUpdateJar'
mustRunAfter(tasks.named('processLauncherResources'))
from "$buildDir/libs/$archivesBaseName-$version-selfupdate.jar"
into "$buildDir/resources/launcher/"
rename "$archivesBaseName-$version-selfupdate.jar", "relauncher-selfupdate.zip"
}
tasks.named('launcherClasses').configure {
dependsOn 'copyAgentJar', 'copySelfUpdateJar'
mustRunAfter(tasks.named('copyAgentJar'))
}
tasks.named('build').configure {
dependsOn('copyAgentJar')
}
tasks.named('shadowJar', ShadowJar).configure {
dependsOn 'copyAgentJar'
from sourceSets.main.output // The logback file
from sourceSets.launcher.output
configurations = [
project.configurations.shade,
project.configurations.logback
]
archiveClassifier.set 'all'
group 'build'
description 'Builds the whole project with its dependencies.'
}
tasks.named(JavaPlugin.JAR_TASK_NAME, Jar).configure {
dependsOn 'generatePomFileForMavenPublication'
from sourceSets.api.output
from sourceSets.launcher.output
exclude 'logback.xml'
into("META-INF/maven/${project.group}/${project.name}") {
from tasks.named('generatePomFileForMavenPublication')
rename 'pom-default.xml', 'pom.xml'
}
manifest.attributes(makeManifestAttributes('Main-Class', application.getMainClass().get()))
description 'Builds the project without its dependencies.'
dependsOn tasks.named('updateLicenses')
}
tasks.register('apiJar', Jar).configure {
from sourceSets.api.output
manifest.attributes(makeManifestAttributes("", ""))
archiveClassifier.set 'api'
description 'Builds the api jar.'
dependsOn tasks.named('updateLicenses')
group 'build'
}
tasks.register('sourcesJar', Jar).configure {
dependsOn 'launcherClasses'
from sourceSets.api.allSource
from sourceSets.launcher.allSource
archiveClassifier.set 'sources'
group 'build'
description 'Builds the sources jar'
}
tasks.register('apiSourcesJar', Jar).configure {
dependsOn 'apiClasses'
from sourceSets.api.allSource
archiveClassifier.set 'api-sources'
group 'build'
description 'Builds the api sources jar'
}
tasks.register('buildAll').configure { // TODO: replace dependsOn in this task to dependsOn in assemble task, and bring back build task
dependsOn("build", "agentJar", "apiJar", "jar", "sourcesJar", "apiSourcesJar")
group 'build'
description 'Runs all the build tasks'
}
def makeManifestAttributes(String extraKey, String extraValue) {
final var actualDateTime = OffsetDateTime.now(ZoneOffset.UTC).withNano(0)
final var currentDateTime = DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(actualDateTime)
final var map = [
'Maven-Artifact' : "${project.group}:${archivesBaseName.toLowerCase()}:${project.version}",
'Timestamp' : currentDateTime,
'Specification-Title' : archivesBaseName,
'Specification-Vendor' : 'Minecraft Mod Development',
'Specification-Version' : '1',
'Implementation-Title' : archivesBaseName,
'Implementation-Version' : "${project.version}",
'Implementation-Vendor' : 'Minecraft Mod Development',
'Implementation-Timestamp': currentDateTime,
'Built-On-Java' : "${System.getProperty('java.vm.version')} (${System.getProperty('java.vm.vendor')})",
]
if (extraKey != null && !extraKey.isBlank()) {
map.put(extraKey, extraValue)
}
return map
}