Skip to content

Commit

Permalink
micronaut framework implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
anilcan.gul authored and osoykan committed Dec 9, 2024
1 parent 4b73d4a commit 3e350f7
Show file tree
Hide file tree
Showing 37 changed files with 888 additions and 24 deletions.
54 changes: 40 additions & 14 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import org.gradle.kotlin.dsl.libs
import org.gradle.plugins.ide.idea.model.IdeaModel
import org.jetbrains.dokka.gradle.DokkaMultiModuleTask
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
Expand All @@ -10,13 +9,12 @@ plugins {
alias(libs.plugins.testLogger)
alias(libs.plugins.kover)
alias(libs.plugins.detekt)
alias(libs.plugins.binaryCompatibilityValidator)
id("stove-publishing") apply false
idea
java
}
group = "com.trendyol"
version = CI.version(project)
version = version()

allprojects {
extra.set("dokka.outputDirectory", rootDir.resolve("docs"))
Expand All @@ -42,21 +40,41 @@ kover {
}
}
}
val related = subprojects.of("lib", "spring", "examples", "ktor")
val related = subprojects.of("lib", "spring", "examples", "ktor", "micronaut-starter")
dependencies {
related.forEach {
kover(it)
}
}

subprojects.of("lib", "spring", "examples", "ktor") {
subprojects.of("lib", "spring", "examples", "ktor", "micronaut-starter") {
apply {
plugin("kotlin")
plugin(rootProject.libs.plugins.spotless.get().pluginId)
plugin(rootProject.libs.plugins.dokka.get().pluginId)
plugin(rootProject.libs.plugins.testLogger.get().pluginId)
plugin(rootProject.libs.plugins.kover.get().pluginId)
plugin(rootProject.libs.plugins.detekt.get().pluginId)
plugin(
rootProject.libs.plugins.spotless
.get()
.pluginId
)
plugin(
rootProject.libs.plugins.dokka
.get()
.pluginId
)
plugin(
rootProject.libs.plugins.testLogger
.get()
.pluginId
)
plugin(
rootProject.libs.plugins.kover
.get()
.pluginId
)
plugin(
rootProject.libs.plugins.detekt
.get()
.pluginId
)
plugin("idea")
}

Expand All @@ -76,13 +94,12 @@ subprojects.of("lib", "spring", "examples", "ktor") {
testImplementation(libs.kotest.runner.junit5)
testImplementation(libs.kotest.framework.api)
testImplementation(libs.kotest.property)
testImplementation(libs.kotest.arrow)
detektPlugins(libs.detekt.formatting)
}

spotless {
kotlin {
ktlint(libs.versions.ktlint.get()).setEditorConfigPath(rootProject.layout.projectDirectory.file(".editorconfig"))
ktlint().setEditorConfigPath(rootProject.layout.projectDirectory.file(".editorconfig"))
targetExclude("build/", "generated/", "out/")
targetExcludeIfContentContains("generated")
targetExcludeIfContentContainsRegex("generated.*")
Expand Down Expand Up @@ -141,10 +158,11 @@ val publishedProjects = listOf(
"stove-testing-e2e-redis",
"stove-ktor-testing-e2e",
"stove-spring-testing-e2e",
"stove-spring-testing-e2e-kafka"
"stove-spring-testing-e2e-kafka",
"stove-micronaut-testing-e2e"
)

subprojects.of("lib", "spring", "ktor", filter = { p -> publishedProjects.contains(p.name) }) {
subprojects.of("lib", "spring", "ktor", "micronaut-starter", filter = { p -> publishedProjects.contains(p.name) }) {
apply {
plugin("java")
plugin("stove-publishing")
Expand All @@ -160,3 +178,11 @@ tasks.withType<DokkaMultiModuleTask>().configureEach {
outputDirectory.set(file(rootDir.resolve("docs/source")))
}

fun version(): String = when {
System.getenv("SNAPSHOT") != null -> {
println("SNAPSHOT: ${System.getenv("SNAPSHOT")}")
project.properties["snapshot"].toString()
}

else -> project.properties["version"].toString()
}
15 changes: 15 additions & 0 deletions examples/micronaut-example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Thumbs.db
.DS_Store
.gradle
build/
target/
out/
.micronaut/
.idea
*.iml
*.ipr
*.iws
.project
.settings
.classpath
.factorypath
81 changes: 81 additions & 0 deletions examples/micronaut-example/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
@file:Suppress("UnstableApiUsage", "DSL_SCOPE_VIOLATION")

plugins {
kotlin("jvm") version libs.versions.kotlin
id("org.jetbrains.kotlin.plugin.allopen") version libs.versions.kotlin
kotlin("plugin.serialization") version libs.versions.kotlin
application
idea
id("com.google.devtools.ksp") version "1.9.25-1.0.20"
id("com.github.johnrengelman.shadow") version "8.1.1"
id("io.micronaut.application") version "4.4.3"
id("io.micronaut.aot") version "4.4.3"
}

repositories {
mavenCentral()
maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots") }
}

dependencies {
runtimeOnly("org.yaml:snakeyaml:2.1")
implementation(platform("io.micronaut.platform:micronaut-parent:4.7.1"))
ksp("io.micronaut:micronaut-http-validation")
ksp("io.micronaut.serde:micronaut-serde-processor")
implementation("io.micronaut.kotlin:micronaut-kotlin-runtime")
implementation("io.micronaut.serde:micronaut-serde-jackson")
implementation("io.micronaut:micronaut-http-client")
implementation("io.micronaut:micronaut-http-server-netty")
implementation("io.micronaut:micronaut-inject")
implementation("io.micronaut:micronaut-core")
runtimeOnly("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("com.couchbase.client:metrics-micrometer:0.7.5")
implementation("io.micronaut.configuration:micronaut-micrometer-core:1.3.1")
implementation("org.apache.kafka:kafka-clients")
implementation(libs.kotlinx.reactor)
implementation(libs.kotlinx.core)
implementation(libs.kotlinx.reactive)
implementation(libs.couchbase.client)
implementation(libs.couchbase.client.metrics)
implementation(libs.jackson.kotlin)
implementation(libs.kotlinx.slf4j)
}

dependencies {
testImplementation(libs.kotest.property)
testImplementation(libs.kotest.runner.junit5)
testImplementation(projects.stove.lib.stoveTestingE2eHttp)
testImplementation(projects.stove.lib.stoveTestingE2eWiremock)
testImplementation(projects.stove.lib.stoveTestingE2eCouchbase)
testImplementation(projects.stove.lib.stoveTestingE2eElasticsearch)
testImplementation(projects.stove.starters.micronautStarter.stoveMicronautTestingE2e)
}

application {
mainClass = "stove.micronaut.example.ApplicationKt"
}

graalvmNative.toolchainDetection = false

java {
sourceCompatibility = JavaVersion.toVersion("17")
}

micronaut {
runtime("netty")
testRuntime("kotest5")
processing {
incremental(true)
annotations("stove.micronaut.example.*")
}
aot {
optimizeServiceLoading = false
convertYamlToJava = false
precomputeOperations = true
cacheEnvironment = true
optimizeClassLoading = true
deduceEnvironment = true
optimizeNetty = true
replaceLogbackXml = true
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package stove.micronaut.example

import io.micronaut.context.ApplicationContext
import io.micronaut.runtime.EmbeddedApplication

fun main(args: Array<String>) {
run(args)
}

fun run(
args: Array<String>,
init: ApplicationContext.() -> Unit = {}
): ApplicationContext {
val context = ApplicationContext
.builder()
.args(*args)
.build()
.also(init)
.start()

context.findBean(EmbeddedApplication::class.java).ifPresent { app ->
if (!app.isRunning) {
app.start()
}
}

return context
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package stove.micronaut.example.application.domain

import io.micronaut.serde.annotation.Serdeable
import java.util.*

@Serdeable
data class Product(
val id: String,
val name: String,
val supplierId: Long,
val isBlacklist: Boolean,
val createdDate: Date
) {
companion object {

fun new(id: String, name: String, supplierId: Long, isBlacklist: Boolean): Product {
return Product(
id = id,
name = name,
supplierId = supplierId,
createdDate = Date(),
isBlacklist = isBlacklist
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package stove.micronaut.example.application.repository

import stove.micronaut.example.application.domain.Product

interface ProductRepository {
suspend fun save(product: Product): Product
suspend fun findById(id: Long): Product?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package stove.micronaut.example.application.services

import jakarta.inject.Singleton
import stove.micronaut.example.application.domain.Product
import stove.micronaut.example.application.repository.ProductRepository
import stove.micronaut.example.infrastructure.http.SupplierHttpService

@Singleton
class ProductService(
private val productRepository: ProductRepository,
private val supplierHttpService: SupplierHttpService
) {
suspend fun createProduct(id: String, productName: String, supplierId: Long): Product {
val supplier = supplierHttpService.getSupplierPermission(supplierId)
val product = Product.new(id, productName, supplierId, supplier!!.isBlacklisted)
productRepository.save(product)
return product
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package stove.micronaut.example.application.services

import io.micronaut.serde.annotation.Serdeable

@Serdeable
data class SupplierPermission(
val id: Long,
val isBlacklisted: Boolean
)

interface SupplierService {
suspend fun getSupplierPermission(supplierId: Long): SupplierPermission?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package stove.micronaut.example.infrastructure.api

import io.micronaut.http.annotation.*
import stove.micronaut.example.application.domain.Product
import stove.micronaut.example.application.services.ProductService
import stove.micronaut.example.infrastructure.api.model.request.CreateProductRequest

@Controller("/products")
class ProductController(
private val productService: ProductService
) {
@Get("/index")
fun get(
@QueryValue keyword: String = "default"
): String = "Hi from Stove framework with $keyword"

@Post("/create")
suspend fun createProduct(
@Body request: CreateProductRequest
): Product = productService.createProduct(
id = request.id,
productName = request.name,
supplierId = request.supplierId
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package stove.micronaut.example.infrastructure.api.model.request

import io.micronaut.serde.annotation.Serdeable

@Serdeable
data class CreateProductRequest(
val id: String,
val name: String,
val supplierId: Long
)
Loading

0 comments on commit 3e350f7

Please sign in to comment.