-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
227 lines (197 loc) · 7.34 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
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
group = "it.pagopa.ecommerce.users"
version = "1.0.1"
description = "pagopa-ecommerce-user-stats-service"
plugins {
id("java")
id("org.springframework.boot") version "3.3.4"
id("io.spring.dependency-management") version "1.1.6"
id("com.diffplug.spotless") version "6.18.0"
id("org.openapi.generator") version "6.3.0"
id("org.sonarqube") version "4.0.0.2929"
id("com.dipien.semantic-version") version "2.0.0" apply false
kotlin("plugin.spring") version "1.8.10"
kotlin("jvm") version "1.9.25"
jacoco
application
}
repositories {
mavenCentral()
mavenLocal()
}
object Dependencies {
const val ecsLoggingVersion = "1.5.0"
const val ioVavrVersion = "0.10.4"
const val jacksonDatabindNullableVersion = "0.2.6"
const val ioSwaggerAnnotationVersion = "2.2.23"
const val mockitoKotlinVersion = "5.4.0"
}
dependencyManagement {
// spring boot BOM
imports { mavenBom("org.springframework.boot:spring-boot-dependencies:3.3.4") }
// spring cloud BOM
imports { mavenBom("com.azure.spring:spring-cloud-azure-dependencies:5.16.0") }
// Kotlin BOM
imports { mavenBom("org.jetbrains.kotlin:kotlin-bom:1.9.25") }
imports { mavenBom("org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.9.0") }
}
dependencies {
// spring dependencies
implementation("io.projectreactor:reactor-core")
implementation("io.projectreactor.netty:reactor-netty")
implementation("org.springframework.boot:spring-boot-starter-webflux")
implementation("org.springframework.boot:spring-boot-starter-validation")
implementation("org.springframework.boot:spring-boot-starter-data-mongodb-reactive")
implementation("org.springframework.boot:spring-boot-starter-actuator")
// spring cloud azure dependencies
implementation("com.azure.spring:spring-cloud-azure-starter")
implementation("com.azure.spring:spring-cloud-azure-starter-data-cosmos")
// Kotlin dependencies
implementation("io.projectreactor.kotlin:reactor-kotlin-extensions")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor")
// openapi generator generated code required dependencies
implementation(
"org.openapitools:jackson-databind-nullable:${Dependencies.jacksonDatabindNullableVersion}"
)
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310")
implementation(
"io.swagger.core.v3:swagger-annotations:${Dependencies.ioSwaggerAnnotationVersion}"
)
// ECS logback encoder
implementation("co.elastic.logging:logback-ecs-encoder:${Dependencies.ecsLoggingVersion}")
runtimeOnly("org.springframework.boot:spring-boot-devtools")
// test dependencies
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("io.projectreactor:reactor-test")
// Kotlin dependencies
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5")
testImplementation("org.mockito.kotlin:mockito-kotlin:${Dependencies.mockitoKotlinVersion}")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
}
configurations {
implementation.configure {
exclude(module = "spring-boot-starter-web")
exclude("org.apache.tomcat")
exclude(group = "org.slf4j", module = "slf4j-simple")
}
}
// Dependency locking - lock all dependencies
dependencyLocking { lockAllConfigurations() }
sourceSets {
main {
java { srcDirs("${layout.buildDirectory.get()}/generated/src/main/java") }
kotlin {
srcDirs("src/main/kotlin", "${layout.buildDirectory.get()}/generated/src/main/kotlin")
}
resources { srcDirs("src/resources") }
}
}
springBoot {
mainClass.set("it.pagopa.ecommerce.users.UserApplicationKt")
buildInfo { properties { additional.set(mapOf("description" to project.description)) } }
}
// compilation configurations
java { toolchain { languageVersion = JavaLanguageVersion.of(21) } }
tasks.withType<KotlinCompile> {
dependsOn("user-stats-v1")
compilerOptions {
apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_1_9)
freeCompilerArgs.addAll("-Xjsr305=strict")
}
}
tasks.create("applySemanticVersionPlugin") {
group = "semantic-versioning"
description = "Semantic versioning plugin"
dependsOn("prepareKotlinBuildScriptModel")
apply(plugin = "com.dipien.semantic-version")
}
tasks.withType(JavaCompile::class.java).configureEach { options.encoding = "UTF-8" }
tasks.withType(Javadoc::class.java).configureEach { options.encoding = "UTF-8" }
configure<com.diffplug.gradle.spotless.SpotlessExtension> {
kotlin {
toggleOffOn()
targetExclude("build/**/*")
ktfmt().kotlinlangStyle()
}
kotlinGradle {
toggleOffOn()
targetExclude("build/**/*.kts")
ktfmt().googleStyle()
}
java {
target("**/*.java")
targetExclude("build/**/*")
eclipse().configFile("eclipse-style.xml")
toggleOffOn()
removeUnusedImports()
trimTrailingWhitespace()
endWithNewline()
}
}
tasks.named<Jar>("jar") { enabled = false }
tasks.test {
useJUnitPlatform()
finalizedBy(tasks.jacocoTestReport) // report is always generated after tests run
}
tasks.jacocoTestReport {
dependsOn(tasks.test) // tests are required to run before generating the report
classDirectories.setFrom(
files(
classDirectories.files.map {
fileTree(it).matching { exclude("it/pagopa/ecommerce/users/UserApplicationKt.class") }
}
)
)
reports { xml.required.set(true) }
}
/**
* Task used to expand application properties with build specific properties such as artifact name
* and version
*/
tasks.processResources { filesMatching("application.properties") { expand(project.properties) } }
/*
* used java generator here instead of kotlin-spring one since kotlin generator generates
* interfaces for one of interface that are not implemented by data concrete data classes
* making code unusable
*/
tasks.register<org.openapitools.generator.gradle.plugin.tasks.GenerateTask>("user-stats-v1") {
group = "code-generator"
description = "Generate stubs from openapi"
generatorName.set("spring")
inputSpec.set("$rootDir/api-spec/v1/user-stats-api.yaml")
outputDir.set("${layout.buildDirectory.get()}/generated")
apiPackage.set("it.pagopa.generated.ecommerce.users.api")
modelPackage.set("it.pagopa.generated.ecommerce.users.model")
generateApiTests.set(false)
generateApiDocumentation.set(false)
generateApiTests.set(false)
generateModelTests.set(false)
library.set("spring-boot")
/*
* Commented out model name suffix because of this issue ->
* /~https://github.com/OpenAPITools/openapi-generator/issues/17343
* that cause discriminator field to not be set properly on deserialized class.
* With model name suffix on the generated code will use the class name as discriminator fields
* for the deserialized responses
*/
// modelNameSuffix.set("Dto")
configOptions.set(
mapOf(
"swaggerAnnotations" to "false",
"openApiNullable" to "true",
"interfaceOnly" to "true",
"hideGenerationTimestamp" to "true",
"skipDefaultInterface" to "true",
"useSwaggerUI" to "false",
"reactive" to "true",
"useSpringBoot3" to "true",
"oas3" to "true",
"generateSupportingFiles" to "true",
"legacyDiscriminatorBehavior" to "true",
"useOneOfInterfaces" to "true",
)
)
}