From fd87cfa0b290ab2e465e78a39d7073c0fa24dcc1 Mon Sep 17 00:00:00 2001 From: Chad Wilson Date: Mon, 17 Jul 2023 00:53:38 +0800 Subject: [PATCH] Upgrade to Micronaut v4 --- build.gradle.kts | 44 +++++++++++++------ .../kotlin/recce/server/RecConfiguration.kt | 2 +- .../server/api/DatasetRecRunController.kt | 11 +++-- .../recce/server/auth/AuthConfiguration.kt | 2 +- .../auth/BasicAuthenticationProvider.kt | 3 +- .../server/dataset/DataLoadDefinition.kt | 2 +- .../server/dataset/DatasetConfiguration.kt | 2 +- .../dataset/datasource/FlywayMigrator.kt | 9 ++-- 8 files changed, 45 insertions(+), 30 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index d102f9b6..d5913447 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,8 +5,7 @@ plugins { id("org.jetbrains.kotlin.jvm") version kotlinVersion id("org.jetbrains.kotlin.kapt") version kotlinVersion id("org.jetbrains.kotlin.plugin.allopen") version kotlinVersion - id("org.jetbrains.kotlin.plugin.jpa") version kotlinVersion - id("io.micronaut.application") version "3.7.10" + id("io.micronaut.application") version "4.1.0" id("com.diffplug.spotless") version "6.19.0" id("io.gitlab.arturbosch.detekt") version "1.23.1" id("com.github.spotbugs") version "5.1.3" @@ -22,12 +21,14 @@ group = "recce.server" // the Gradle DSL properly. Here we pick one of the versions where multiple artifacts are released at the same time // and use this to bump the others consistently. val depDescriptors = mapOf( - "micronaut" to "io.micronaut:micronaut-core:4.0.2", + "micronautPlatform" to "io.micronaut.platform:micronaut-platform:4.1.1", + "micronautCore" to "io.micronaut:micronaut-core-bom:4.1.5", "restAssured" to "io.rest-assured:rest-assured:4.5.1" ) val depVersions = depDescriptors.mapValues { (_, v) -> v.split(':').last() } + mapOf( "javaMajor" to "17", - "reactorToolsVersionExpected" to "3.5.10" + "kotlin" to "1.9.0", + "reactorToolsExpected" to "3.5.10" ) repositories { @@ -42,10 +43,15 @@ tasks.withType().configureEach kotlinOptions { allWarningsAsErrors = true } + compilerOptions { + jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17) + } } micronaut { - version(depVersions["micronaut"]) + version(depVersions["micronautPlatform"]) + coreVersion.set(depVersions["micronautCore"]) + runtime("netty") testRuntime("junit5") processing { @@ -77,15 +83,27 @@ configurations.all { } dependencies { - kapt("io.micronaut:micronaut-http-validation") kapt("io.micronaut.data:micronaut-data-processor") - implementation("io.micronaut:micronaut-runtime") - implementation("io.micronaut:micronaut-validation") + kapt("io.micronaut:micronaut-http-validation") + kapt("io.micronaut.serde:micronaut-serde-processor") + + implementation("io.micronaut.serde:micronaut-serde-jackson") + implementation("jakarta.validation:jakarta.validation-api") + implementation("org.jetbrains.kotlin:kotlin-reflect:${depVersions["kotlin"]}") + implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:${depVersions["kotlin"]}") + implementation("io.micronaut.serde:micronaut-serde-jackson") + runtimeOnly("org.yaml:snakeyaml") + + kapt("io.micronaut.validation:micronaut-validation-processor") + implementation("io.micronaut.validation:micronaut-validation") + implementation("jakarta.validation:jakarta.validation-api") + implementation("io.micronaut.kotlin:micronaut-kotlin-runtime") implementation("io.micronaut.security:micronaut-security-jwt") - implementation("javax.annotation:javax.annotation-api") + implementation("jakarta.annotation:jakarta.annotation-api") implementation("com.google.guava:guava:32.1.2-jre") { // see https://github.com/google/guava/pull/6606 + exclude(module = "listenablefuture") exclude(module = "error_prone_annotations") exclude(module = "checker-qual") exclude(module = "jsr305") @@ -277,7 +295,7 @@ jib { ports = listOf("8080") environment = mapOf("version" to version.toString()) labels.set(mapOf("org.opencontainers.image.source" to "https://github.com/$githubRepoOwner/recce")) - jvmFlags = listOf("-javaagent:/app/libs/reactor-tools-${depVersions["reactorToolsVersionExpected"]}.jar") + jvmFlags = listOf("-javaagent:/app/libs/reactor-tools-${depVersions["reactorToolsExpected"]}.jar") } } @@ -286,10 +304,10 @@ val checkJibDependencies = tasks.register("checkJibDependencies") { val resolvedReactorToolsVersion = project.configurations.runtimeClasspath.get() .resolvedConfiguration.resolvedArtifacts.find { it.name == "reactor-tools" }?.moduleVersion?.id?.version - if (depVersions["reactorToolsVersionExpected"] != resolvedReactorToolsVersion) { + if (depVersions["reactorToolsExpected"] != resolvedReactorToolsVersion) { throw GradleException( - "Jib docker build expected reactor-tools [${depVersions["reactorToolsVersionExpected"]}] but found " + - "[$resolvedReactorToolsVersion] in dependencies. Update reactorToolsVersionExpected!" + "Jib docker build expected reactor-tools [${depVersions["reactorToolsExpected"]}] but found " + + "[$resolvedReactorToolsVersion] in dependencies. Update reactorToolsExpected!" ) } } diff --git a/src/main/kotlin/recce/server/RecConfiguration.kt b/src/main/kotlin/recce/server/RecConfiguration.kt index 89fa8803..e226d477 100644 --- a/src/main/kotlin/recce/server/RecConfiguration.kt +++ b/src/main/kotlin/recce/server/RecConfiguration.kt @@ -5,11 +5,11 @@ import io.micronaut.context.annotation.ConfigurationInject import io.micronaut.context.annotation.ConfigurationProperties import io.micronaut.context.annotation.Context import io.micronaut.core.bind.annotation.Bindable +import jakarta.annotation.PostConstruct import mu.KotlinLogging import recce.server.dataset.DatasetConfiguration import recce.server.dataset.HashingStrategy import java.nio.file.Path -import javax.annotation.PostConstruct import kotlin.io.path.Path private val logger = KotlinLogging.logger {} diff --git a/src/main/kotlin/recce/server/api/DatasetRecRunController.kt b/src/main/kotlin/recce/server/api/DatasetRecRunController.kt index 0dece8cf..13f2f38a 100644 --- a/src/main/kotlin/recce/server/api/DatasetRecRunController.kt +++ b/src/main/kotlin/recce/server/api/DatasetRecRunController.kt @@ -10,6 +10,10 @@ import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.media.Schema import io.swagger.v3.oas.annotations.responses.ApiResponse import jakarta.inject.Inject +import jakarta.validation.Valid +import jakarta.validation.constraints.Max +import jakarta.validation.constraints.NotBlank +import jakarta.validation.constraints.PositiveOrZero import mu.KotlinLogging import reactor.core.publisher.Flux import reactor.core.publisher.Mono @@ -18,10 +22,6 @@ import reactor.kotlin.core.util.function.component2 import recce.server.dataset.DatasetRecRunner import recce.server.recrun.RecRecordRepository import recce.server.recrun.RecRunRepository -import javax.validation.Valid -import javax.validation.constraints.Max -import javax.validation.constraints.NotBlank -import javax.validation.constraints.PositiveOrZero private val logger = KotlinLogging.logger {} @@ -38,7 +38,7 @@ class DatasetRecRunController( @Introspected data class IndividualRunQueryParams( @field:Schema(description = "The identifier of the reconciliation run to retrieve") - @field:PathVariable + @field:PathVariable("runId") val runId: Int, @field:Schema( @@ -53,7 +53,6 @@ class DatasetRecRunController( ) @Get(uri = "/{runId}{?includeSampleKeys}") - @Suppress("MnUnresolvedPathVariable") @Operation( summary = "Retrieve details of an individual run by ID for a dataset", tags = ["Reconciliation Runs"], diff --git a/src/main/kotlin/recce/server/auth/AuthConfiguration.kt b/src/main/kotlin/recce/server/auth/AuthConfiguration.kt index 74e73b2f..8996f72f 100644 --- a/src/main/kotlin/recce/server/auth/AuthConfiguration.kt +++ b/src/main/kotlin/recce/server/auth/AuthConfiguration.kt @@ -3,7 +3,7 @@ package recce.server.auth import io.micronaut.context.annotation.ConfigurationInject import io.micronaut.context.annotation.ConfigurationProperties import jakarta.inject.Singleton -import javax.validation.constraints.NotBlank +import jakarta.validation.constraints.NotBlank @Singleton @ConfigurationProperties("auth") diff --git a/src/main/kotlin/recce/server/auth/BasicAuthenticationProvider.kt b/src/main/kotlin/recce/server/auth/BasicAuthenticationProvider.kt index 6775070a..564054cf 100644 --- a/src/main/kotlin/recce/server/auth/BasicAuthenticationProvider.kt +++ b/src/main/kotlin/recce/server/auth/BasicAuthenticationProvider.kt @@ -11,7 +11,8 @@ import reactor.core.publisher.Flux import reactor.core.publisher.FluxSink @Singleton -class BasicAuthenticationProvider(private val authConfiguration: AuthConfiguration) : AuthenticationProvider { +class BasicAuthenticationProvider(private val authConfiguration: AuthConfiguration) : + AuthenticationProvider> { override fun authenticate( httpRequest: HttpRequest<*>?, authenticationRequest: AuthenticationRequest<*, *> diff --git a/src/main/kotlin/recce/server/dataset/DataLoadDefinition.kt b/src/main/kotlin/recce/server/dataset/DataLoadDefinition.kt index c1ec02d8..3e94163f 100644 --- a/src/main/kotlin/recce/server/dataset/DataLoadDefinition.kt +++ b/src/main/kotlin/recce/server/dataset/DataLoadDefinition.kt @@ -6,6 +6,7 @@ import io.micronaut.context.exceptions.ConfigurationException import io.micronaut.data.r2dbc.operations.R2dbcOperations import io.micronaut.inject.qualifiers.Qualifiers import io.r2dbc.spi.Result +import jakarta.validation.constraints.NotBlank import org.jetbrains.annotations.TestOnly import reactor.core.publisher.Flux import reactor.kotlin.core.util.function.component1 @@ -14,7 +15,6 @@ import recce.server.DefaultsProvider import recce.server.PostConstructable import java.nio.file.Path import java.util.* -import javax.validation.constraints.NotBlank import kotlin.io.path.readText class DataLoadDefinition diff --git a/src/main/kotlin/recce/server/dataset/DatasetConfiguration.kt b/src/main/kotlin/recce/server/dataset/DatasetConfiguration.kt index c35fddc9..a3dab462 100644 --- a/src/main/kotlin/recce/server/dataset/DatasetConfiguration.kt +++ b/src/main/kotlin/recce/server/dataset/DatasetConfiguration.kt @@ -4,12 +4,12 @@ import io.micronaut.context.BeanLocator import io.micronaut.core.annotation.Nullable import io.micronaut.core.bind.annotation.Bindable import io.micronaut.scheduling.cron.CronExpression +import jakarta.validation.constraints.NotNull import org.jetbrains.annotations.TestOnly import recce.server.DefaultsProvider import recce.server.PostConstructable import java.time.ZonedDateTime import java.util.* -import javax.validation.constraints.NotNull class DatasetConfiguration( @NotNull val source: DataLoadDefinition, diff --git a/src/test/kotlin/recce/server/dataset/datasource/FlywayMigrator.kt b/src/test/kotlin/recce/server/dataset/datasource/FlywayMigrator.kt index d3944431..fe8773ef 100644 --- a/src/test/kotlin/recce/server/dataset/datasource/FlywayMigrator.kt +++ b/src/test/kotlin/recce/server/dataset/datasource/FlywayMigrator.kt @@ -1,6 +1,6 @@ package recce.server.dataset.datasource -import io.micronaut.transaction.annotation.TransactionalAdvice +import io.micronaut.transaction.annotation.Transactional import jakarta.inject.Inject import jakarta.inject.Named import jakarta.inject.Singleton @@ -9,7 +9,6 @@ import org.flywaydb.core.api.configuration.FluentConfiguration import java.nio.file.Files import java.nio.file.Path import javax.sql.DataSource -import javax.transaction.Transactional @Singleton open class FlywayMigrator { @@ -36,8 +35,7 @@ open class FlywayMigrator { @field:Named("target-h2-sync") lateinit var targetDataSource: DataSource - @Transactional - @TransactionalAdvice(transactionManager = "source-h2-sync") + @Transactional(transactionManager = "source-h2-sync") open fun cleanMigrateSource( tempDir: Path, sql: String = createTable + (0..2).joinToString("\n", transform = insertUser) @@ -45,8 +43,7 @@ open class FlywayMigrator { flywayCleanMigrate(tempDir, sql) { it.dataSource(sourceDataSource) } } - @Transactional - @TransactionalAdvice(transactionManager = "target-h2-sync") + @Transactional(transactionManager = "target-h2-sync") open fun cleanMigrateTarget( tempDir: Path, sql: String = createTable + ((0..1) + (3..4)).joinToString("\n", transform = insertUser)