-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.gradle.kts
261 lines (226 loc) · 8.21 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
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
import java.util.*
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("app.cash.licensee:licensee-gradle-plugin:1.7.0")
}
}
apply(plugin = "app.cash.licensee")
plugins {
id("com.diffplug.spotless")
id("org.mikeneck.graalvm-native-image")
id("com.github.johnrengelman.shadow")
id("com.apollographql.apollo3")
id("com.avast.gradle.docker-compose")
id("io.gitlab.arturbosch.detekt")
kotlin("jvm")
}
val cliGroup: String by project
val projectVersion: String by project
val apolloVersion: String by project
val commonsLang3Version: String by project
val cliktVersion: String by project
val bouncycastleVersion: String by project
val jupiterVersion: String by project
val commonsIoVersion: String by project
val auth0JwtVersion: String by project
val vertxVersion: String by project
val slf4jVersion: String by project
group = cliGroup
version = project.properties["cliVersion"] as String? ?: projectVersion
repositories {
mavenCentral()
maven(url = "https://pkg.sourceplus.plus/sourceplusplus/protocol")
}
val graphqlLibs = configurations.create("graphqlLibs")
dependencies {
implementation("com.apollographql.apollo3:apollo-runtime:$apolloVersion")
api("com.apollographql.apollo3:apollo-api:$apolloVersion")
implementation("plus.sourceplus:protocol:$projectVersion")
graphqlLibs("plus.sourceplus:protocol:$projectVersion")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3")
implementation("org.slf4j:slf4j-api:$slf4jVersion")
implementation("org.slf4j:slf4j-nop:$slf4jVersion")
implementation("io.vertx:vertx-core:$vertxVersion")
implementation("io.vertx:vertx-tcp-eventbus-bridge:$vertxVersion")
implementation("io.vertx:vertx-lang-kotlin-coroutines:$vertxVersion")
implementation("org.apache.commons:commons-lang3:$commonsLang3Version")
implementation("com.github.ajalt.clikt:clikt:$cliktVersion")
implementation("org.bouncycastle:bcprov-jdk15on:$bouncycastleVersion")
implementation("org.bouncycastle:bcpkix-jdk15on:$bouncycastleVersion")
implementation("commons-io:commons-io:$commonsIoVersion")
implementation("com.auth0:java-jwt:$auth0JwtVersion")
implementation("eu.geekplace.javapinning:java-pinning-core:1.2.0")
testImplementation("org.junit.jupiter:junit-jupiter-engine:$jupiterVersion")
testImplementation("org.slf4j:slf4j-simple:$slf4jVersion")
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.23.1")
}
//remove slf4j-nop from test classpath (use slf4j-simple instead)
tasks.withType<Test> {
useJUnitPlatform()
classpath = classpath.filter { !it.toString().contains("slf4j-nop") }
}
configure<app.cash.licensee.LicenseeExtension> {
ignoreDependencies("plus.sourceplus", "protocol")
allow("Apache-2.0")
allow("MIT")
allowUrl("https://raw.githubusercontent.com/apollographql/apollo-kotlin/main/LICENSE") //MIT
allowUrl("https://raw.githubusercontent.com/auth0/java-jwt/master/LICENSE") //MIT
allowUrl("https://www.bouncycastle.org/licence.html") //MIT
}
//todo: shouldn't need to put in src (github actions needs for some reason)
tasks.create("createProperties") {
if (System.getProperty("build.profile") == "release") {
val buildBuildFile = File(projectDir, "src/main/resources/build.properties")
if (buildBuildFile.exists()) {
buildBuildFile.delete()
} else {
buildBuildFile.parentFile.mkdirs()
}
buildBuildFile.writer().use {
val p = Properties()
p["build_id"] = UUID.randomUUID().toString()
p["build_date"] = Date().toInstant().toString()
p["build_version"] = project.version.toString()
p.store(it, null)
}
}
}
tasks["processResources"].dependsOn("createProperties")
configurations {
create("empty")
}
nativeImage {
dependsOn("shadowJar")
setClasspath(File(project.buildDir, "libs/spp-cli-${project.version}.jar"))
runtimeClasspath = configurations.getByName("empty")
if (System.getenv("GRAALVM_HOME") != null) {
graalVmHome = System.getenv("GRAALVM_HOME")
}
buildType { build ->
build.executable(main = "spp.cli.Main")
}
executableName = "spp-cli"
outputDirectory = file("$buildDir/graal")
arguments("--no-fallback")
arguments("-H:+ReportExceptionStackTraces")
}
tasks.getByName<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar>("shadowJar") {
archiveBaseName.set("spp-cli")
archiveClassifier.set("")
manifest {
attributes(
mapOf(
"Main-Class" to "spp.cli.Main"
)
)
}
}
tasks.getByName("build").dependsOn("shadowJar")
configurations.runtimeClasspath {
exclude("ch.qos.logback", "logback-classic")
}
tasks.getByName<Test>("test") {
useJUnitPlatform()
val isIntegrationProfile = System.getProperty("test.profile") == "integration"
val runningSpecificTests = gradle.startParameter.taskRequests.isNotEmpty()
//exclude integration tests unless requested
if (!isIntegrationProfile && !runningSpecificTests) {
exclude("integration/**", "**/*IntegrationTest.class", "**/*ITTest.class")
}
testLogging {
events("passed", "skipped", "failed")
setExceptionFormat("full")
outputs.upToDateWhen { false }
showStandardStreams = true
}
}
tasks {
register("assembleUp") {
dependsOn("assemble", "composeUp")
}
getByName("composeUp").mustRunAfter("assemble")
}
dockerCompose {
waitForTcpPorts.set(false)
}
apollo {
service("service") {
packageNamesFromFilePaths("spp.cli.protocol")
}
}
//todo: find specific task to add dependsOn() to
//ensure graphqlLibs() dependency is available
tasks.all {
if (findProject(":protocol") != null) {
dependsOn(":protocol:jar")
}
}
tasks.create<Copy>("importProtocolFiles") {
configurations.getByName("graphqlLibs").asFileTree.forEach {
if (it.name.startsWith("protocol-")) {
from(zipTree(it)) {
exclude("META-INF/**")
exclude("spp/**")
}
}
}
into(file("src/main"))
}
tasks.getByName("checkApolloVersions").dependsOn("importProtocolFiles")
tasks.getByName("test").dependsOn("importProtocolFiles")
tasks.getByName("generateServiceApolloSchema").dependsOn("importProtocolFiles")
tasks.getByName("generateServiceApolloUsedCoordinates").dependsOn("importProtocolFiles")
tasks.getByName("processResources").dependsOn("importProtocolFiles")
tasks.getByName("detekt").dependsOn("importProtocolFiles")
spotless {
kotlin {
targetExclude("**/generated/**")
val startYear = 2022
val currentYear = Calendar.getInstance().get(Calendar.YEAR)
val copyrightYears = if (startYear == currentYear) {
"$startYear"
} else {
"$startYear-$currentYear"
}
val jetbrainsProject = findProject(":protocol") ?: rootProject
val licenseHeader = Regex("( . Copyright [\\S\\s]+)")
.find(File(jetbrainsProject.projectDir, "LICENSE").readText())!!
.value.lines().joinToString("\n") {
if (it.trim().isEmpty()) {
" *"
} else {
" * " + it.trim()
}
}
val formattedLicenseHeader = buildString {
append("/*\n")
append(
licenseHeader.replace(
"Copyright [yyyy] [name of copyright owner]",
"Source++, the continuous feedback platform for developers.\n" +
" * Copyright (C) $copyrightYears CodeBrig, Inc."
).replace(
"http://www.apache.org/licenses/LICENSE-2.0",
" http://www.apache.org/licenses/LICENSE-2.0"
)
)
append("/")
}
licenseHeader(formattedLicenseHeader)
}
}
detekt {
parallel = true
buildUponDefaultConfig = true
config.setFrom(arrayOf(File(project.rootDir, "detekt.yml")))
}
tasks.withType<JavaCompile> {
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class) {
kotlinOptions.jvmTarget = "1.8"
}