Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Micronaut v4 #438

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 31 additions & 13 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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.21.0"
id("io.gitlab.arturbosch.detekt") version "1.23.1"
id("com.github.spotbugs") version "5.1.3"
Expand All @@ -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:3.10.1",
"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 {
Expand All @@ -42,10 +43,15 @@ tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().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 {
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
}
}

Expand All @@ -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!"
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/recce/server/RecConfiguration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down
11 changes: 5 additions & 6 deletions src/main/kotlin/recce/server/api/DatasetRecRunController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {}

Expand All @@ -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(
Expand All @@ -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"],
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/recce/server/auth/AuthConfiguration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<HttpRequest<*>> {
override fun authenticate(
httpRequest: HttpRequest<*>?,
authenticationRequest: AuthenticationRequest<*, *>
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/recce/server/dataset/DataLoadDefinition.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 {
Expand All @@ -36,17 +35,15 @@ 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)
) {
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)
Expand Down