-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.gradle.kts
209 lines (171 loc) · 5.91 KB
/
build.gradle.kts
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
plugins {
java
application
jacoco // code coverage reports
id("com.diffplug.spotless") version "6.18.0"
}
repositories {
maven {
url = uri("https://m2.dv8tion.net/releases")
name = "m2-dv8tion"
content {
includeGroup("net.dv8tion")
includeGroup("com.sedmelluq")
}
}
maven {
url = uri("https://m2.chew.pro/snapshots")
name = "m2-chew"
content { includeGroup("pw.chew") }
}
maven {
url = uri("https://jitpack.io")
name = "jitpack"
}
mavenCentral()
}
sourceSets {
create("testShared") {
compileClasspath += sourceSets["main"].output
runtimeClasspath += sourceSets["main"].output
}
named("test") {
compileClasspath += sourceSets["testShared"].output
runtimeClasspath += sourceSets["testShared"].output
}
create("testIntegration") {
compileClasspath += sourceSets["testShared"].output + sourceSets["main"].output
runtimeClasspath += sourceSets["testShared"].output + sourceSets["main"].output
}
}
dependencies {
val testsImplementation = { dependencyNotation: Any ->
"testImplementation"(dependencyNotation)
"testIntegrationImplementation"(dependencyNotation)
"testSharedImplementation"(dependencyNotation)
}
implementation("com.google.guava:guava:31.1-jre")
implementation("com.github.ben-manes.caffeine:caffeine:3.1.2")
implementation("com.google.code.gson:gson:2.9.1")
implementation("com.github.Marcono1234:gson-record-type-adapter-factory:v0.3.0")
implementation("net.dv8tion:JDA:5.0.0-beta.2")
implementation("com.github.black0nion:Pagination-Utils:3.3.0")
// this commit contains an unreleased fix for JDA Alpha .21
implementation("com.github.Chew:JDA-Chewtils:5e1a9f93f9")
implementation("com.github.Mokulu:discord-oauth2-api:1.0.2")
implementation("io.javalin:javalin-bundle:5.4.2")
implementation("com.auth0:java-jwt:4.4.0")
// reading public and private keys
implementation("org.bouncycastle:bcprov-jdk18on:1.72")
implementation("org.json:json:20220924")
implementation("club.minnced:discord-webhooks:0.8.2")
implementation("se.michaelthelin.spotify:spotify-web-api-java:7.2.2")
implementation("com.vdurmont:emoji-java:5.1.1")
implementation("org.reflections:reflections:0.10.2")
implementation("com.google.zxing:core:3.5.1")
implementation("com.google.zxing:javase:3.5.1")
implementation("ch.qos.logback:logback-classic:1.4.6")
implementation("uk.org.lidalia:sysout-over-slf4j:1.0.2")
implementation("io.prometheus:simpleclient_logback:0.16.0")
implementation("com.github.loki4j:loki-logback-appender:1.3.2")
implementation("org.codehaus.janino:janino:3.1.9")
implementation("io.github.classgraph:classgraph:4.8.151")
implementation("org.postgresql:postgresql:42.6.0")
implementation("com.zaxxer:HikariCP:5.0.1")
implementation("io.prometheus:simpleclient:0.16.0")
implementation("io.prometheus:simpleclient_hotspot:0.16.0")
implementation("io.prometheus:simpleclient_httpserver:0.16.0")
testsImplementation("org.junit.jupiter:junit-jupiter:5.9.1")
testsImplementation("com.github.erosb:everit-json-schema:1.14.1")
testsImplementation("org.mockito:mockito-core:4.9.0")
}
configurations { all { exclude(group = "org.slf4j", module = "slf4j-log4j12") } }
application { mainClass.set("com.github.black0nion.blackonionbot.Main") }
version = System.getenv("VERSION") ?: "dev"
tasks.named<Jar>("jar") { archiveVersion.set("") }
tasks.compileJava { options.release.set(19) }
tasks.test {
useJUnitPlatform()
finalizedBy(tasks.jacocoTestReport) // report is always generated after tests run
// dependsOn testIntegration
dependsOn(testIntegration)
}
val testIntegration by
tasks.registering(Test::class) {
description = "Runs integration tests."
group = "verification"
testClassesDirs = sourceSets["testIntegration"].output.classesDirs
classpath = sourceSets["testIntegration"].runtimeClasspath
shouldRunAfter(tasks.test)
useJUnitPlatform()
}
spotless {
kotlinGradle {
target("**/*.gradle.kts")
ktfmt("0.39").dropboxStyle()
trimTrailingWhitespace()
indentWithTabs()
endWithNewline()
}
}
tasks.jacocoTestReport {
group = "Reporting"
description = "Generate Jacoco coverage reports after running tests."
reports {
xml.required.set(true)
html.required.set(true)
}
finalizedBy("jacocoTestCoverageVerification")
}
configurations {
getByName("testIntegrationImplementation").extendsFrom(implementation.get())
getByName("testIntegrationRuntimeOnly").extendsFrom(runtimeOnly.get())
getByName("testSharedImplementation").extendsFrom(implementation.get())
getByName("testSharedRuntimeOnly").extendsFrom(runtimeOnly.get())
}
/**
* This task downloads all dependencies (with transitive dependencies) and puts them into the
* libraries folder. Used instead of shadowJar to hopefully optimize build times. Run the
* application jar with the downloaded library files in the classpath.
*/
tasks.register("downloadDependencies") {
description = "Downloads all dependencies and puts them into the libraries folder."
group = "build"
doLast {
logger.lifecycle("Downloading dependencies...")
val dependencies =
configurations["runtimeClasspath"].resolvedConfiguration.resolvedArtifacts
val librariesFolder = File("libraries")
librariesFolder.mkdirs()
dependencies.forEach { artifact ->
logger.lifecycle("Downloading ${artifact.file.name}...")
val file = artifact.file
val targetFile = File(librariesFolder, file.name)
if (!targetFile.exists()) {
file.copyTo(targetFile)
}
}
logger.lifecycle("Done downloading dependencies.")
}
}
tasks.processResources {
val locAndFiles = getLoc()
filesMatching("bot.metadata.json") {
expand("version" to version, "lines_of_code" to locAndFiles[0], "files" to locAndFiles[1])
}
}
fun getLoc(): List<Int> {
var linesOfCode = 0
var filesCount = 0
project.sourceSets["main"].allSource.srcDirs.forEach { dir ->
if (dir.isDirectory) {
dir.listFiles()?.forEach { file ->
if (file.isFile) {
file.forEachLine { linesOfCode++ }
filesCount++
}
}
}
}
return listOf(linesOfCode, filesCount)
}