-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
225 lines (197 loc) · 6.92 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
@file:Suppress("UnstableApiUsage")
import com.google.protobuf.gradle.id
import com.vanniktech.maven.publish.SonatypeHost
import org.jlleitschuh.gradle.ktlint.reporter.ReporterType
// define the gav coordinates of this project
group = "net.scrayos"
version = "0.8.3-SNAPSHOT"
description = "Xenos Client (Kotlin/Java)"
// hook the plugins for the builds
plugins {
alias(libs.plugins.idea)
alias(libs.plugins.javaLibrary)
alias(libs.plugins.kotlin)
alias(libs.plugins.dokka)
alias(libs.plugins.kover)
alias(libs.plugins.protobuf)
alias(libs.plugins.sonarqube)
alias(libs.plugins.ktlint)
alias(libs.plugins.mavenPublish)
}
// configure the repositories for the dependencies
repositories {
// official maven repository
mavenCentral()
}
// declare all dependencies (for compilation and runtime)
dependencies {
// add gRPC dependencies that are necessary for compilation and execution
implementation(libs.bundles.grpc)
// add coroutines for our coroutine-based communication
implementation(libs.kotlin.coroutines.core)
// compile against the slf4j API for logging
compileOnly(libs.slf4j)
// specify test dependencies
testImplementation(libs.kotlin.test)
testImplementation(libs.bundles.kotest)
testImplementation(libs.bundles.log4j)
testRuntimeOnly(libs.grpc.netty)
}
// configure the kotlin extension
kotlin {
// set the toolchain version required to build this project
// replaces sourceCompatibility and targetCompatibility as it also sets these implicitly
// https://kotlinlang.org/docs/gradle-configure-project.html#gradle-java-toolchains-support
jvmToolchain(17)
}
// configure the protobuf extension (protoc + grpc)
protobuf {
// configure the protobuf compiler for the proto compilation
protoc {
// set the artifact for protoc (the compiler version to use)
artifact = libs.protoc.core.get().toString()
}
// configure the plugins for the protobuf build process
plugins {
// add a new "grpc" plugin for the java stub generation
id("grpc") {
// set the artifact for protobuf code generation (stubs)
artifact = libs.protoc.genJava.get().toString()
}
// add a new "grpckt" plugin for the kotlin stub generation
id("grpckt") {
artifact = libs.protoc.genKotlin.get().toString() + ":jdk8@jar"
}
}
// configure the proto tasks (extraction, generation, etc.)
generateProtoTasks {
// only modify the main source set, we don't have any proto files in test
all().configureEach {
// apply the "java" and "kotlin" builtin tasks as we are compiling against java and kotlin
builtins {
// id("java") – is added implicitly by default
id("kotlin")
}
// apply the "grpc" and "grpckt" plugins whose specs are defined above, without special options
plugins {
id("grpc")
id("grpckt")
}
}
}
}
// configure testing suites within Gradle check phase
testing {
suites {
val test by getting(JvmTestSuite::class) {
useJUnitJupiter(libs.versions.junit)
}
}
}
// configure publishing for the sonatype portal
mavenPublishing {
// add the central portal of Sonatype
publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL, automaticRelease = true)
// configure mandatory metadata for Maven Central
pom {
name.set("Xenos Client (Kotlin/Java)")
description.set("A gRPC client/binding for the communication with Xenos.")
inceptionYear.set("2024")
url.set("https://github.com/scrayosnet/xenos-client-kotlin/")
licenses {
license {
name.set("MIT License")
url.set("https://opensource.org/license/mit")
distribution.set("repo")
}
}
developers {
developer {
id.set("scrayos")
name.set("Joshua Dean Küpper")
url.set("https://github.com/scrayos/")
}
}
scm {
url.set("https://github.com/scrayosnet/xenos-client-kotlin/")
connection.set("scm:git:git://github.com/scrayosnet/xenos-client-kotlin.git")
developerConnection.set("scm:git:ssh://[email protected]/scrayosnet/xenos-client-kotlin.git")
}
}
// sign all exported publications
signAllPublications()
}
// configure the publishing in the maven repository
publishing {
// define the repositories that shall be used for publishing
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/scrayosnet/xenos-client-kotlin")
credentials {
username = System.getenv("GITHUB_ACTOR")
password = System.getenv("GITHUB_TOKEN")
}
}
}
}
// configure ktlint
ktlint {
// explicitly use a recent ktlint version for latest checks
version = libs.versions.ktlint
// exclude any generated files
filter {
// exclude generated protobuf files
exclude { element -> element.file.path.contains("/generated/") }
}
// configure the reporting to use checkstyle syntax
reporters {
reporter(ReporterType.PLAIN)
reporter(ReporterType.CHECKSTYLE)
reporter(ReporterType.SARIF)
}
}
// configure dokka
dokka {
dokkaSourceSets {
configureEach {
perPackageOption {
matchingRegex.set("scrayosnet.xenos.*")
suppress = true
}
}
}
}
// configure sonarqube plugin
sonarqube {
properties {
property("sonar.projectKey", "scrayosnet_xenos-client-kotlin")
property("sonar.organization", "scrayosnet")
property("sonar.projectName", "xenos-client-kotlin")
property("sonar.projectVersion", version)
property("sonar.projectDescription", description!!)
property("sonar.host.url", "https://sonarcloud.io")
property(
"sonar.kotlin.ktlint.reportPaths",
"build/reports/ktlint/ktlintKotlinScriptCheck/ktlintKotlinScriptCheck.xml," +
"build/reports/ktlint/ktlintMainSourceSetCheck/ktlintMainSourceSetCheck.xml," +
"build/reports/ktlint/ktlintTestSourceSetCheck/ktlintTestSourceSetCheck.xml",
)
property("sonar.coverage.jacoco.xmlReportPaths", "build/reports/kover/report.xml")
}
}
// configure tasks
tasks {
jar {
// exclude the proto files as we won't need them in downstream projects
exclude("**/*.proto")
// exclude the now empty folders (because the proto files were removed)
includeEmptyDirs = false
// remove duplicates from the final jar
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
javadoc {
// exclude the generated protobuf files
exclude("scrayosnet/xenos/**")
}
}