This repository has been archived by the owner on Aug 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
build.gradle
341 lines (292 loc) · 9 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
plugins {
id 'java'
id 'application'
id 'com.github.johnrengelman.shadow' version '5.2.0'
}
def versionObj = new Version(major: 0, minor: 20, revision: 2)
sourceCompatibility = 15
targetCompatibility = 15
allprojects {
group 'com.github.natanbc'
version versionObj.toString()
repositories {
jcenter()
maven { url 'https://dl.bintray.com/natanbc/maven' }
maven { url 'https://dl.bintray.com/sedmelluq/com.sedmelluq' }
maven { url 'https://m2.dv8tion.net/releases' }
maven { url 'https://jitpack.io' }
}
}
ext {
//@formatter:off
configVersion = '1.4.0'
jdaNasVersion = '1.1.0'
jsr305Version = '3.0.2'
koeVersion = '1864a8b803'
nettyEpollVersion = '4.1.52.Final'
nettyKQueueVersion = '4.1.52.Final'
lavaplayerVersion = '1.3.76'
lpcrossVersion = '0.1.1'
ytRotatorVersion = '0.1.7'
lavadspVersion = '0.7.6'
logbackVersion = '1.2.3'
magmaVersion = '0.12.5'
nativeLoaderVersion = '0.7.0'
prometheusVersion = '0.9.0'
sentryVersion = '1.7.30'
vertxWebVersion = '3.9.3'
jattachVersion = 'v1.5'
//@formatter:on
}
mainClassName = 'andesite.Andesite'
dependencies {
implementation project(':api')
//Config
implementation "com.typesafe:config:$configVersion"
//REST, WebSocket, etc
implementation "io.vertx:vertx-web:$vertxWebVersion"
//Audio sending
implementation "space.npstr.Magma:magma:$magmaVersion"
//Audio sending
implementation("moe.kyokobot.koe:core:$koeVersion") {
exclude group: "org.slf4j", module: "slf4j-api"
}
implementation("moe.kyokobot.koe:ext-udpqueue:$koeVersion") {
exclude group: 'com.sedmelluq', module: 'udp-queue'
}
//Native transports
implementation "io.netty:netty-transport-native-epoll:$nettyEpollVersion:linux-x86_64"
implementation "io.netty:netty-transport-native-kqueue:$nettyKQueueVersion:osx-x86_64"
//Audio player
implementation("com.sedmelluq:lavaplayer:$lavaplayerVersion") {
exclude group: 'com.sedmelluq', module: 'lavaplayer-natives'
}
implementation "com.github.natanbc:lp-cross:$lpcrossVersion"
//IPv6 rotation
implementation("com.sedmelluq:lavaplayer-ext-youtube-rotator:$ytRotatorVersion") {
exclude group: 'com.sedmelluq', module: 'lavaplayer'
}
//Audio filters
implementation "com.github.natanbc:lavadsp:$lavadspVersion"
//Native library loading
implementation "com.github.natanbc:native-loader:$nativeLoaderVersion"
//Native send system
implementation("com.sedmelluq:jda-nas:$jdaNasVersion") {
exclude group: 'com.sedmelluq', module: 'udp-queue'
}
//Logger implementation
implementation "ch.qos.logback:logback-classic:$logbackVersion"
//Error tracking
implementation "io.sentry:sentry:$sentryVersion"
implementation "io.sentry:sentry-logback:$sentryVersion"
//Metrics
implementation "io.prometheus:simpleclient:$prometheusVersion"
implementation "io.prometheus:simpleclient_hotspot:$prometheusVersion"
implementation "io.prometheus:simpleclient_logback:$prometheusVersion"
//Code safety
implementation "com.google.code.findbugs:jsr305:$jsr305Version"
}
def natives = [
'all',
'darwin',
'freebsd-x86-64',
'linux-aarch64',
'linux-arm',
'linux-x86',
'linux-x86-64',
'linux-musl-aarch64',
'linux-musl-x86-64',
'win-x86',
'win-x86-64'
]
task buildAll {}
task buildImages {}
buildAll.dependsOn ':jattach-debug-plugin:jar'
buildAll.dependsOn ':api:jar'
buildAll.dependsOn ':api:javadoc'
task ci {
dependsOn buildAll
dependsOn buildImages
}
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
jar {
manifest {
attributes(
'Main-Class': mainClassName
)
}
}
natives.each { arch ->
def shadowTask = task("shadow-${arch}", type: ShadowJar) {
archiveClassifier.set(arch)
from project.sourceSets.main.output
configurations = [ project.configurations.runtimeClasspath ]
manifest.inheritFrom project.tasks.jar.manifest
exclude 'natives/linux-aarch32/**'
exclude 'natives/linux-armhf/**'
exclude 'module-info.class'
exclude 'lombok/**'
exclude 'vertx-web-js/**'
exclude 'vertx-web/**'
exclude 'vertx-auth-common-js/**'
exclude 'vertx-auth-common/**'
exclude 'vertx-bridge-common-js/**'
exclude 'vertx-bridge-common/**'
exclude 'vertx-core/**'
exclude 'Class50/**'
exclude 'com/zwitserloot/**'
exclude 'secondaryLoading.SCL.lombok/**'
if(arch != 'all') {
natives.each {
if(it != arch) {
exclude "natives/${it}/**"
}
}
}
}
buildAll.dependsOn shadowTask
}
def baseTags = ["natanbc/andesite:${getCommitHash()}"]
//only set latest tag for releases, so `docker pull natanbc/andesite`
//pulls the latest stable version
if(System.getenv("TAG") != null && !System.getenv("TAG").trim().isEmpty()) {
baseTags << "natanbc/andesite:${version}"
baseTags << "natanbc/andesite:latest"
}
buildImages.dependsOn createDockerBuild(
"normal",
file("Dockerfile"),
baseTags,
(ShadowJar)rootProject.tasks.findByName("shadow-linux-x86-64")
)
buildImages.dependsOn createDockerBuild(
"alpine",
file("musl/Dockerfile"),
baseTags.collect {"$it-alpine" },
(ShadowJar)rootProject.tasks.findByName("shadow-linux-musl-x86-64")
)
def lint = [
"auxiliaryclass",
"cast",
"deprecation",
"dep-ann",
"divzero",
"empty",
"exports",
"fallthrough",
"finally",
"module",
"opens",
"options",
"overloads",
"overrides",
"path",
"rawtypes",
"removal",
"static",
"try",
"unchecked",
"varargs",
"preview"
]
import org.apache.tools.ant.filters.ReplaceTokens
task sourcesForRelease(type: Copy) {
from ('src/main/java') {
include '**/Version.java'
filter(ReplaceTokens, tokens: [
VERSION_MAJOR: versionObj.major,
VERSION_MINOR: versionObj.minor,
VERSION_REVISION: versionObj.revision,
COMMIT: getCommitHash(),
BUILD_NUMBER: getBuildNumber()
])
}
into 'build/filteredSrc'
includeEmptyDirs = false
}
task generateJavaSources(type: SourceTask) {
def javaSources = sourceSets.main.allJava.filter {
it.name != 'Version.java'
}
source = javaSources + sourcesForRelease.destinationDir
dependsOn sourcesForRelease
}
compileJava {
source = generateJavaSources.source
dependsOn generateJavaSources
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
options.incremental = true
options.compilerArgs += ["-Xlint:${lint.join(",")}", "-Werror"]
}
compileTestJava.enabled = false
processTestResources.enabled = false
class Version {
String major, minor, revision
String toString() {
"$major.$minor.$revision"
}
}
static def getCommitHash() {
def p = Runtime.getRuntime().exec("git rev-parse HEAD")
p.waitFor()
p.getIn().text.trim()
}
def createDockerBuild(String name, File dockerfile, List<String> tags, ShadowJar shadowTask) {
if(!dockerfile.exists()) {
throw new Exception("Dockerfile '$dockerfile' doesn't exist")
}
def dir = new File(project.buildDir, "docker/$name")
dir.mkdirs()
def jarTask = (org.gradle.jvm.tasks.Jar)tasks.getByPath(":jattach-debug-plugin:jar")
def copyResults = tasks.create("dockerCopy-$name", Copy) {
from(shadowTask.outputs) {
include "*.jar"
}
from(jarTask.outputs) {
include "*.jar"
}
from('.') {
include "jlink.sh"
}
into dir
}
def dockerBuild = tasks.create("dockerBuild-$name", Exec) {
dependsOn copyResults
workingDir dir
executable = 'docker'
def argList = [
"build",
"-f",
dockerfile.getAbsolutePath(),
"--build-arg",
"version=${rootProject.version}",
"--build-arg",
"jattachVersion=${jattachVersion}",
]
tags.each { argList << "-t" << it }
argList << "."
args = argList
}
return dockerBuild
}
def getBuildNumber() {
def properties = [
"BUILD_NUMBER",
"TRAVIS_BUILD_NUMBER",
"GITHUB_RUN_ID"
]
for(name in properties) {
String property
if(hasProperty(name)) {
property = project.properties[name]
} else {
property = System.getenv(name) ?: ""
}
if(property != "") {
return property
}
}
return "unable to find build number"
}