forked from navikt/mock-oauth2-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
300 lines (268 loc) · 9.68 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
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
import java.time.Duration
import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
val assertjVersion = "3.24.2"
val kotlinLoggingVersion = "3.0.5"
val logbackVersion = "1.4.11"
val nimbusSdkVersion = "11.5"
val mockWebServerVersion = "4.12.0"
val jacksonVersion = "2.15.3"
val nettyVersion = "4.1.100.Final"
val junitJupiterVersion = "5.10.0"
val kotlinVersion = "1.9.10"
val freemarkerVersion = "2.3.32"
val kotestVersion = "5.7.2"
val bouncyCastleVersion = "1.70"
val springBootVersion = "3.1.5"
val reactorTestVersion = "3.5.11"
val ktorVersion = "2.3.5"
val mavenRepoBaseUrl = "https://oss.sonatype.org"
val mainClassKt = "no.nav.security.mock.oauth2.StandaloneMockOAuth2ServerKt"
plugins {
application
kotlin("jvm") version "1.9.10"
id("se.patrikerdes.use-latest-versions") version "0.2.18"
id("com.github.ben-manes.versions") version "0.49.0"
id("org.jmailen.kotlinter") version "4.0.0"
id("com.google.cloud.tools.jib") version "3.4.0"
id("com.github.johnrengelman.shadow") version "8.1.1"
id("net.researchgate.release") version "3.0.2"
id("io.github.gradle-nexus.publish-plugin") version "1.3.0"
id("org.jetbrains.dokka") version "1.9.10"
`java-library`
`maven-publish`
signing
}
application {
mainClass.set(mainClassKt)
}
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
withJavadocJar()
withSourcesJar()
}
apply(plugin = "org.jmailen.kotlinter")
repositories {
mavenCentral()
}
dependencies {
implementation(kotlin("stdlib"))
implementation(kotlin("reflect"))
implementation("com.fasterxml.jackson.core:jackson-databind:$jacksonVersion")
implementation("ch.qos.logback:logback-classic:$logbackVersion")
api("com.squareup.okhttp3:mockwebserver:$mockWebServerVersion")
api("com.nimbusds:oauth2-oidc-sdk:$nimbusSdkVersion")
implementation("io.netty:netty-all:$nettyVersion")
implementation("io.github.microutils:kotlin-logging:$kotlinLoggingVersion")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:$jacksonVersion")
implementation("org.freemarker:freemarker:$freemarkerVersion")
implementation("org.bouncycastle:bcpkix-jdk15on:$bouncyCastleVersion")
testImplementation("org.assertj:assertj-core:$assertjVersion")
testImplementation("org.junit.jupiter:junit-jupiter-api:$junitJupiterVersion")
testImplementation("org.junit.jupiter:junit-jupiter-params:$junitJupiterVersion")
testImplementation("io.kotest:kotest-runner-junit5-jvm:$kotestVersion") // for kotest framework
testImplementation("io.kotest:kotest-assertions-core-jvm:$kotestVersion") // for kotest core jvm assertions
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5:$kotlinVersion")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$junitJupiterVersion")
// example use with different frameworks
testImplementation("org.springframework.boot:spring-boot-starter-webflux:$springBootVersion")
testImplementation("org.springframework.boot:spring-boot-starter-oauth2-resource-server:$springBootVersion")
testImplementation("org.springframework.boot:spring-boot-starter-oauth2-client:$springBootVersion")
testImplementation("org.springframework.boot:spring-boot-starter-test:$springBootVersion")
testImplementation("org.springframework.boot:spring-boot-test:$springBootVersion")
constraints {
testImplementation("org.yaml:snakeyaml:2.2") {
because("previous versions have security vulnerabilities")
}
add("api", "com.squareup.okio:okio") {
version {
require("3.4.0")
}
}
add("testImplementation", "com.google.guava:guava") {
version {
require("32.1.2-jre")
}
}
}
testImplementation("io.projectreactor:reactor-test:$reactorTestVersion")
testImplementation("io.ktor:ktor-server-netty:$ktorVersion")
testImplementation("io.ktor:ktor-server-sessions:$ktorVersion")
testImplementation("io.ktor:ktor-server-locations:$ktorVersion")
testImplementation("io.ktor:ktor-server-auth:$ktorVersion")
testImplementation("io.ktor:ktor-server-auth-jwt:$ktorVersion")
testImplementation("io.ktor:ktor-server-content-negotiation:$ktorVersion")
testImplementation("io.ktor:ktor-client-core:$ktorVersion")
testImplementation("io.ktor:ktor-client-content-negotiation:$ktorVersion")
testImplementation("io.ktor:ktor-serialization-jackson:$ktorVersion")
testImplementation("io.ktor:ktor-client-cio:$ktorVersion")
testImplementation("io.ktor:ktor-server-test-host:$ktorVersion")
}
configurations {
all {
resolutionStrategy.force("com.fasterxml.woodstox:woodstox-core:6.5.1")
}
}
nexusPublishing {
packageGroup.set("no.nav")
clientTimeout.set(Duration.ofMinutes(2))
repositories {
sonatype {
username.set(System.getenv("SONATYPE_USERNAME"))
password.set(System.getenv("SONATYPE_PASSWORD"))
}
}
transitionCheckOptions {
maxRetries.set(60)
delayBetween.set(Duration.ofMillis(10000))
}
}
publishing {
publications {
create<MavenPublication>("mavenJava") {
artifactId = rootProject.name
from(components["java"])
versionMapping {
usage("java-api") {
fromResolutionOf("runtimeClasspath")
}
usage("java-runtime") {
fromResolutionResult()
}
}
pom {
name.set(rootProject.name)
description.set("A simple mock oauth2 server based on OkHttp MockWebServer")
url.set("https://github.com/navikt/${rootProject.name}")
licenses {
license {
name.set("MIT License")
url.set("https://opensource.org/licenses/MIT")
}
}
developers {
developer {
organization.set("NAV (Arbeids- og velferdsdirektoratet) - The Norwegian Labour and Welfare Administration")
organizationUrl.set("https://www.nav.no")
}
}
scm {
connection.set("scm:git:git://github.com/navikt/${rootProject.name}.git")
developerConnection.set("scm:git:ssh://github.com/navikt/${rootProject.name}.git")
url.set("https://github.com/navikt/${rootProject.name}")
}
}
}
}
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/navikt/${rootProject.name}")
credentials {
username = System.getenv("GITHUB_ACTOR")
password = System.getenv("GITHUB_TOKEN")
}
}
}
}
ext["signing.gnupg.keyName"] = System.getenv("GPG_KEY_NAME")
ext["signing.gnupg.passphrase"] = System.getenv("GPG_PASSPHRASE")
ext["signing.gnupg.executable"] = "gpg"
signing {
useGpgCmd()
sign(publishing.publications["mavenJava"])
}
tasks.javadoc {
if (JavaVersion.current().isJava9Compatible) {
(options as StandardJavadocDocletOptions).addBooleanOption("html5", true)
}
}
jib {
from {
platforms {
platform {
architecture = "amd64"
os = "linux"
}
platform {
architecture = "arm64"
os = "linux"
}
}
image = "gcr.io/distroless/java17-debian11"
}
container {
ports = listOf("8080")
mainClass = mainClassKt
}
}
(components["java"] as AdhocComponentWithVariants).withVariantsFromConfiguration(configurations["shadowRuntimeElements"]) {
skip()
}
fun isNonStable(version: String): Boolean {
val stableKeyword = listOf("RELEASE", "FINAL", "GA").any { version.uppercase().contains(it) }
val regex = "^[0-9,.v-]+(-r)?$".toRegex()
val isStable = stableKeyword || regex.matches(version)
return isStable.not()
}
tasks.named("dependencyUpdates", DependencyUpdatesTask::class.java).configure {
this.resolutionStrategy {
componentSelection {
all {
if (isNonStable(candidate.version)) {
reject("Release candidate")
}
}
}
}
}
tasks.named("useLatestVersions", se.patrikerdes.UseLatestVersionsTask::class.java).configure {
updateBlacklist = listOf(
"io.codearte:nexus-staging"
)
}
// This task is added by Gradle when we use java.withJavadocJar()
tasks.named<Jar>("javadocJar") {
from(tasks.named("dokkaJavadoc"))
}
buildscript {
dependencies {
configurations.classpath.get().exclude("xerces", "xercesImpl")
}
}
tasks {
withType<org.jmailen.gradle.kotlinter.tasks.LintTask> {
dependsOn("formatKotlin")
}
withType<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar> {
archiveBaseName.set("app")
archiveClassifier.set("")
manifest {
attributes(
mapOf(
"Main-Class" to mainClassKt
)
)
}
}
withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_17.toString()
}
}
withType<Test> {
jvmArgs("--add-opens=java.base/java.util=ALL-UNNAMED")
useJUnitPlatform()
}
"jibDockerBuild" {
dependsOn("shadowJar")
}
withType<Sign>().configureEach {
onlyIf {
System.getenv("GPG_KEYS") != null
}
}
withType<Wrapper> {
gradleVersion = "8.3"
}
}