-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.gradle
391 lines (333 loc) · 14.3 KB
/
build.gradle
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin"
// TODO: might be removed when https://hibernate.atlassian.net/browse/HHH-13354 is resolved
classpath "org.hibernate:hibernate-gradle-plugin:$hibernateGradlePluginVersion"
}
}
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm'
// Kotlin annotations processor (needed by Micronaut)
id 'org.jetbrains.kotlin.kapt'
// Needed for Bean Validation https://docs.micronaut.io/latest/guide/index.html#beanValidation.
// Unsure, if there is another reason for it.
// TODO: configure allopen to only open @Validated classes
id 'org.jetbrains.kotlin.plugin.allopen'
// Check updated dependencies with "./gradlew dependencyUpdates".
id 'com.github.ben-manes.versions'
// Release version with "./gradlew release".
id 'net.researchgate.release'
// Bundle all dependencies into one fat shadowed jar.
// (Gets automatically triggered when application plugin is present)
id 'com.github.johnrengelman.shadow'
// Add no-argument constructors as they are needed for JPA (see https://kotlinlang.org/docs/reference/compiler-plugins.html#jpa-support).
id "org.jetbrains.kotlin.plugin.jpa"
// Plugin for gRPC protobuf generation
id 'com.google.protobuf'
// List all licenses in "build/reports/dependency-license" with "./gradlew generateLicenseReport".
id 'com.github.jk1.dependency-license-report'
// Adds the following plugins (see https://micronaut-projects.github.io/micronaut-gradle-plugin/latest/):
// io.micronaut.minimal.application
// Adds application plugin
// Adds java plugin
// Adds distribution plugin
// Run with "./gradlew run"
// Generates start scripts; is executed on "build" task but not on e.g. "jar" task.
// io.micronaut.graalvm
// Build GraalVM native-image with "./gradlew nativeCompile"
// Run with "./gradlew nativeRun"
// Relies on https://graalvm.github.io/native-build-tools/latest/gradle-plugin.html)
// io.micronaut.docker
id "io.micronaut.application" version "3.5.1"
}
// Enhance Hibernate entities (see configuration block below).
// TODO: move to plugins block when https://hibernate.atlassian.net/browse/HHH-13354 is resolved
apply plugin: 'org.hibernate.orm'
repositories {
mavenCentral()
// mavenLocal()
// maven {
// url "https://jitpack.io"
//// // Workaround to be able to specify a git hash as jitpack version
//// metadataSources {
//// artifact()
//// }
// }
}
dependencies {
// If no specific version is defined, it might be provided by the Micronaut BOM
// Kotlin
/// Provide kotlin-reflect although not used, as the jackson-kotlin module might provide its own, but maybe for an earlier Kotlin version, which would mess up things (or at least yield warnings).
implementation "org.jetbrains.kotlin:kotlin-reflect"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinCoroutinesVersion"
// Tests
/// JUnit
testImplementation "org.junit.jupiter:junit-jupiter-api"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine"
testImplementation "org.junit.jupiter:junit-jupiter-params"
testImplementation "io.micronaut.test:micronaut-test-junit5"
/// Mockito
//testImplementation "org.mockito:mockito-junit-jupiter:$mockitoJunitJupiterVersion"
/// Assertions
testImplementation "org.assertj:assertj-core:$assertjVersion"
// Logging
// See http://saltnlight5.blogspot.com/2013/08/how-to-configure-slf4j-with-different.html for a quick introduction to slf4j
implementation "io.github.microutils:kotlin-logging-jvm:$kotlinLoggingVersion"
runtimeOnly "ch.qos.logback:logback-classic:$logbackVersion"
runtimeOnly "net.logstash.logback:logstash-logback-encoder:$logstashLogbackVersion"
runtimeOnly "com.mattbertolini:liquibase-slf4j:$liquibaseSlf4jVersion" // makes Liquibase use SLF4J instead of java.util.logging
runtimeOnly "org.slf4j:jcl-over-slf4j:$jclOverSlf4jVersion" // redirect Jakarta/Apache Commons Logging to SLF4J
// Micronaut Bill of Materials, which defines dependency versions
implementation platform("io.micronaut:micronaut-bom:$micronautVersion")
kapt platform("io.micronaut:micronaut-bom:$micronautVersion")
kaptTest platform("io.micronaut:micronaut-bom:$micronautVersion")
// Micronaut Core
implementation "io.micronaut:micronaut-runtime"
implementation "io.micronaut.kotlin:micronaut-kotlin-runtime"
implementation "javax.annotation:javax.annotation-api"
runtimeOnly "com.fasterxml.jackson.module:jackson-module-kotlin"
implementation 'org.reactivestreams:reactive-streams' // seems to be needed in Micronaut 3.0.1
// Micronaut Inversion of Control / Dependency Injection
kapt "io.micronaut:micronaut-inject-java"
kaptTest "io.micronaut:micronaut-inject-java"
testAnnotationProcessor "io.micronaut:micronaut-inject-java"
// Micronaut Reactive
//implementation "io.micronaut.rxjava2:micronaut-rxjava2" // use RxJava2 for existing implementations (e.g. ConfigurableCredentialAuthenticationProvider)
implementation "io.micronaut.reactor:micronaut-reactor"
implementation "io.micronaut.reactor:micronaut-reactor-http-client"
// Micronaut Validation
kapt "io.micronaut:micronaut-validation"
//implementation 'io.micronaut.configuration:micronaut-hibernate-validator' // if full Bean Validator 2.0 compliance is needed
// Micronaut HTTP Server
implementation "io.micronaut:micronaut-http-server-netty"
// Micronaut HTTP Client
implementation "io.micronaut:micronaut-http-client"
// Micronaut Management & Monitoring
/// Automatically provides the /health endpoint publicly, and some other with authentication
implementation 'io.micronaut:micronaut-management'
//implementation 'io.micronaut.configuration:micronaut-jmx' // activate JMX for the endpoints
// Micronaut Persistence
kapt "io.micronaut.data:micronaut-data-processor"
implementation "io.micronaut.data:micronaut-data-hibernate-jpa"
/// JDBC Connection Pooling
runtimeOnly "io.micronaut.sql:micronaut-jdbc-hikari"
//runtimeOnly "io.micronaut.sql:micronaut-jdbc-tomcat"
//runtimeOnly "io.micronaut.sql:micronaut-jdbc-dbcp"
/// Database drivers
runtimeOnly "com.h2database:h2"
runtimeOnly "org.mariadb.jdbc:mariadb-java-client:$mariadbVersion"
//runtimeOnly "org.postgresql:postgresql:$postgresqlVersion"
//runtimeOnly "org.hsqldb:hsqldb:$hsqldbVersion"
//runtimeOnly "org.apache.derby:derby:$derbyVersion"
/// Database Migration
implementation "io.micronaut.liquibase:micronaut-liquibase"
// Micronaut Security
kapt "io.micronaut.security:micronaut-security-annotations"
implementation "io.micronaut.security:micronaut-security"
// Micronaut Service registration and discovery
implementation "io.micronaut.discovery:micronaut-discovery-client"
// Micronaut OpenAPI integration
kapt "io.micronaut.openapi:micronaut-openapi"
implementation "io.swagger.core.v3:swagger-annotations"
// Micronaut Views
//implementation "io.micronaut.views:micronaut-views-thymeleaf"
//implementation "io.micronaut.views:micronaut-views-handlebars"
//implementation "io.micronaut.views:micronaut-views-velocity"
//implementation "io.micronaut.views:micronaut-views-freemarker"
//implementation "io.micronaut.views:micronaut-views-rocker"
//implementation "io.micronaut.views:micronaut-views-soy"
// Micronaut gRPC
implementation "io.micronaut.grpc:micronaut-grpc-server-runtime"
implementation "io.micronaut.grpc:micronaut-grpc-client-runtime"
implementation "io.grpc:grpc-services:$grpcVersion"
implementation "io.grpc:grpc-kotlin-stub:$grpcKotlinVersion"
// Debuglevel Microservice Commons
//implementation "com.github.debuglevel:microservice-commons:f24dd3964f"
}
ext {
_group = applicationGroup
_module = applicationModule
_mainClass = _group + "." + _module + ".Application"
_title = applicationTitle
}
// Java configuration
java {
sourceCompatibility = JavaVersion.VERSION_17 // Source code is this Java version
targetCompatibility = JavaVersion.VERSION_17 // Byte code will be this JVM version
}
// Kotlin configuration
tasks {
compileKotlin {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_17 // Byte code will be this JVM version
javaParameters = true // Retain parameter names for Java reflection
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_17 // Byte code will be this JVM version
javaParameters = true // Retain parameter names for Java reflection
}
}
}
// TODO: Might be already be set through micronaut plugin
// Enable gradle incremental annotation processing for Java.
tasks.withType(JavaCompile) {
options.compilerArgs = [
"-Amicronaut.processing.incremental=true",
"-Amicronaut.processing.annotations=${_group}.*",
"-Amicronaut.processing.group=${_group}",
"-Amicronaut.processing.module=${_module}",
]
}
// Enable gradle incremental annotation processing for Kotlin.
kapt {
arguments {
arg("micronaut.processing.incremental", true)
arg("micronaut.processing.annotations", "${_group}.*")
arg("micronaut.processing.group", _group)
arg("micronaut.processing.module", _module)
}
}
// Micronaut configuration
micronaut {
runtime("netty")
testRuntime("junit5")
processing {
incremental(true)
annotations(_group + "." + _module + ".*")
}
}
// application plugin configuration
application {
mainClass = _mainClass
applicationName = _title
}
// Enhance Hibernate entities in byte code.
hibernate {
enhance {
enableLazyInitialization = true
enableDirtyTracking = true
enableAssociationManagement = true
}
}
allOpen {
annotation("io.micronaut.aop.Around")
//// open @Singleton for Mockito
//annotation("javax.inject.Singleton")
}
// Generate gRPC source from proto
protobuf {
protoc { artifact = "com.google.protobuf:protoc:$protocVersion" }
plugins {
grpc { artifact = "io.grpc:protoc-gen-grpc-java:$grpcVersion" }
grpckt { artifact = "io.grpc:protoc-gen-grpc-kotlin:$grpcKotlinVersion:jdk8@jar" }
}
generateProtoTasks {
all()*.plugins {
grpc {}
grpckt {}
}
}
}
sourceSets {
main {
java {
srcDirs 'build/generated/source/proto/main/grpc'
srcDirs 'build/generated/source/proto/main/grpckt'
srcDirs 'build/generated/source/proto/main/java'
}
}
}
// Copy the openapi.yaml file generated by Micronaut to the root folder.
tasks.register('copyOpenAPI', Copy) {
description "Copies the generated OpenAPI YAML file into the project base directory."
dependsOn ['kaptKotlin']
from "build/tmp/kapt3/classes/main/META-INF/swagger"
into "."
include "*.yml"
rename ".*\\.yml", "openapi.yaml"
doNotTrackState("No idea, failed without this statement (at least on Windows).")
}
compileJava.dependsOn tasks.named("copyOpenAPI")
compileKotlin.dependsOn tasks.named("copyOpenAPI")
generateProto.dependsOn tasks.named("copyOpenAPI")
processResources.dependsOn tasks.named("copyOpenAPI")
processTestResources.dependsOn tasks.named("copyOpenAPI")
// Jar configuration
jar {
// Add Manifest to jar
manifest {
attributes 'Implementation-Title': applicationTitle,
'Implementation-Version': archiveVersion,
'Main-Class': _mainClass
}
}
// Appends entries in META-INF/services resources into a single resource. Not sure, if needed.
// See: https://github.com/johnrengelman/shadow/blob/master/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/transformers/ServiceFileTransformer.groovy
shadowJar {
mergeServiceFiles()
}
graalvmNative {
binaries {
main {
// imageName = 'application' // Name of the native image (default: project name)
// debug = true // Generate debug info (default: false)
// verbose = true // Add verbose output (default: false)
// fallback = false // Generate fallback native-image (default: false)
// quickBuild = true // Build in quick build mode (default: false); GRAALVM_QUICK_BUILD environment variable might override it.
// Show trace of class initialization
// buildArgs.add("--trace-class-initialization=kotlin.KotlinVersion,kotlin.jvm.internal.Reflection")
buildArgs.add("-H:DeadlockWatchdogInterval=340") // Set watchdog interval to 60 minutes
}
}
}
// Deactivate zip generations in distributions folder as they are not very useful and take relatively much build time.
tasks.distZip.enabled = false
tasks.shadowDistZip.enabled = false
// Configuration of net.researchgate.release plugin
release {
failOnCommitNeeded = true // Fail because changed files would be committed automatically
failOnUnversionedFiles = false // Don't fail because non-versioned files would not be committed automatically
git {
requireBranch.set('/master|main/')
}
}
test {
useJUnitPlatform()
testLogging {
events "passed", "skipped", "failed"
}
reports {
html.required = true
}
}
// Filter out beta versions et cetera on dependency update check.
dependencyUpdates.resolutionStrategy {
componentSelection { rules ->
rules.all { ComponentSelection selection ->
boolean rejected = ['alpha', 'beta', 'rc', 'cr', 'm', 'preview', 'b', 'ea', 'pr'].any { qualifier ->
selection.candidate.version ==~ /(?i).*[.-]$qualifier[.\d-+]*/
}
if (rejected) {
selection.reject('Release candidate')
}
}
}
}
// -XX:TieredStopAtLevel=1 limits optimizations of the HotSpot compiler and its runtime overhead (reduce startup time)
tasks.withType(JavaExec) {
//classpath += configurations.developmentOnly
jvmArgs('-XX:TieredStopAtLevel=1', '-Dcom.sun.management.jmxremote')
if (gradle.startParameter.continuous) {
systemProperties(
'micronaut.io.watch.restart': 'true',
'micronaut.io.watch.enabled': 'true',
"micronaut.io.watch.paths": "src/main"
)
}
}