From b0ef004c144b0d52f80577a09f72c7c6d8345a9d Mon Sep 17 00:00:00 2001 From: khalilou88 <32600911+khalilou88@users.noreply.github.com> Date: Fri, 29 Dec 2023 01:15:06 +0100 Subject: [PATCH] add micronaut kt projects (#12) * add micronaut kt projects * work in progress * work in progress --- .gitignore | 1 + .../micronaut-kt-app/aot-jar.properties | 34 +++ nx-maven/micronaut/micronaut-kt-app/pom.xml | 259 ++++++++++++++++++ .../micronaut/micronaut-kt-app/project.json | 51 ++++ .../micronaut/micronautktapp/Application.kt | 7 + .../micronautktapp/HelloController.kt | 17 ++ .../src/main/resources/application.properties | 2 + .../src/main/resources/logback.xml | 15 + .../micronautktapp/HelloControllerTest.kt | 22 ++ .../MicronautMicronautKtAppTest.kt | 18 ++ .../src/test/resources/application.properties | 2 + nx-maven/micronaut/micronaut-kt-lib/pom.xml | 201 ++++++++++++++ .../micronaut/micronaut-kt-lib/project.json | 38 +++ .../micronaut/micronautktlib/HelloService.kt | 10 + .../micronautktlib/HelloServiceTest.kt | 18 ++ nx-maven/pom.xml | 2 + 16 files changed, 697 insertions(+) create mode 100644 nx-maven/micronaut/micronaut-kt-app/aot-jar.properties create mode 100644 nx-maven/micronaut/micronaut-kt-app/pom.xml create mode 100644 nx-maven/micronaut/micronaut-kt-app/project.json create mode 100644 nx-maven/micronaut/micronaut-kt-app/src/main/kotlin/com/example/micronaut/micronautktapp/Application.kt create mode 100644 nx-maven/micronaut/micronaut-kt-app/src/main/kotlin/com/example/micronaut/micronautktapp/HelloController.kt create mode 100644 nx-maven/micronaut/micronaut-kt-app/src/main/resources/application.properties create mode 100644 nx-maven/micronaut/micronaut-kt-app/src/main/resources/logback.xml create mode 100644 nx-maven/micronaut/micronaut-kt-app/src/test/kotlin/com/example/micronaut/micronautktapp/HelloControllerTest.kt create mode 100644 nx-maven/micronaut/micronaut-kt-app/src/test/kotlin/com/example/micronaut/micronautktapp/MicronautMicronautKtAppTest.kt create mode 100644 nx-maven/micronaut/micronaut-kt-app/src/test/resources/application.properties create mode 100644 nx-maven/micronaut/micronaut-kt-lib/pom.xml create mode 100644 nx-maven/micronaut/micronaut-kt-lib/project.json create mode 100644 nx-maven/micronaut/micronaut-kt-lib/src/main/kotlin/com/example/micronaut/micronautktlib/HelloService.kt create mode 100644 nx-maven/micronaut/micronaut-kt-lib/src/test/kotlin/com/example/micronaut/micronautktlib/HelloServiceTest.kt diff --git a/.gitignore b/.gitignore index 6e97fbe..4e360f6 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ node_modules # IDEs and editors .idea +*.iml .project .classpath .c9/ diff --git a/nx-maven/micronaut/micronaut-kt-app/aot-jar.properties b/nx-maven/micronaut/micronaut-kt-app/aot-jar.properties new file mode 100644 index 0000000..71049dc --- /dev/null +++ b/nx-maven/micronaut/micronaut-kt-app/aot-jar.properties @@ -0,0 +1,34 @@ +# AOT configuration properties for jar packaging +# Please review carefully the optimizations enabled below +# Check https://micronaut-projects.github.io/micronaut-aot/latest/guide/ for more details + +# Caches environment property values: environment properties will be deemed immutable after application startup. +cached.environment.enabled=true + +# Precomputes Micronaut configuration property keys from the current environment variables +precompute.environment.properties.enabled=true + +# Converts YAML configuration files to Java configuration +yaml.to.java.config.enabled=true + +# Scans for service types ahead-of-time, avoiding classpath scanning at startup +serviceloading.jit.enabled=true + +# Scans reactive types at build time instead of runtime +scan.reactive.types.enabled=true + +# Deduces the environment at build time instead of runtime +deduce.environment.enabled=true + +# Checks of existence of some types at build time instead of runtime +known.missing.types.enabled=true + +# Precomputes property sources at build time +sealed.property.source.enabled=true + +# The list of service types to be scanned (comma separated) +service.types=io.micronaut.context.env.PropertySourceLoader,io.micronaut.inject.BeanConfiguration,io.micronaut.inject.BeanDefinitionReference,io.micronaut.http.HttpRequestFactory,io.micronaut.http.HttpResponseFactory,io.micronaut.core.beans.BeanIntrospectionReference,io.micronaut.core.convert.TypeConverterRegistrar,io.micronaut.context.env.PropertyExpressionResolver + +# A list of types that the AOT analyzer needs to check for existence (comma separated) +known.missing.types.list=io.reactivex.Observable,reactor.core.publisher.Flux,kotlinx.coroutines.flow.Flow,io.reactivex.rxjava3.core.Flowable,io.reactivex.rxjava3.core.Observable,io.reactivex.Single,reactor.core.publisher.Mono,io.reactivex.Maybe,io.reactivex.rxjava3.core.Single,io.reactivex.rxjava3.core.Maybe,io.reactivex.Completable,io.reactivex.rxjava3.core.Completable,io.methvin.watchservice.MacOSXListeningWatchService,io.micronaut.core.async.publisher.CompletableFuturePublisher,io.micronaut.core.async.publisher.Publishers.JustPublisher,io.micronaut.core.async.subscriber.Completable + diff --git a/nx-maven/micronaut/micronaut-kt-app/pom.xml b/nx-maven/micronaut/micronaut-kt-app/pom.xml new file mode 100644 index 0000000..7a23615 --- /dev/null +++ b/nx-maven/micronaut/micronaut-kt-app/pom.xml @@ -0,0 +1,259 @@ + + + 4.0.0 + micronaut-kt-app + ${packaging} + micronaut-kt-app + This project was generated with nx-maven + + + com.example + micronaut-parent-project + ${revision} + ../micronaut-parent-project/pom.xml + + + + jar + netty + false + + com.example.micronaut.micronautktapp.aot.generated + + + com.example.micronaut.micronautktapp.ApplicationKt + + + + + + central + https://repo.maven.apache.org/maven2 + + + + + + io.micronaut + micronaut-http-server-netty + compile + + + io.micronaut.kotlin + micronaut-kotlin-runtime + compile + + + io.micronaut.serde + micronaut-serde-jackson + compile + + + org.jetbrains.kotlin + kotlin-reflect + ${kotlin.version} + compile + + + org.jetbrains.kotlin + kotlin-stdlib-jdk8 + ${kotlin.version} + compile + + + ch.qos.logback + logback-classic + runtime + + + com.fasterxml.jackson.module + jackson-module-kotlin + runtime + + + io.micronaut + micronaut-http-client + test + + + io.micronaut.test + micronaut-test-junit5 + test + + + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-engine + test + + + com.example + micronaut-kt-lib + ${project.version} + + + + + + + io.micronaut.maven + micronaut-maven-plugin + + aot-${packaging}.properties + + + + org.apache.maven.plugins + maven-enforcer-plugin + + + kotlin-maven-plugin + org.jetbrains.kotlin + ${kotlin.version} + + ${java.version} + + all-open + + + + + + + + kapt + + kapt + + + + ${project.basedir}/src/main/kotlin + + + + io.micronaut + micronaut-inject-java + ${micronaut.version} + + + io.micronaut + micronaut-graal + ${micronaut.version} + + + io.micronaut.serde + micronaut-serde-processor + ${micronaut.serialization.version} + + + + + micronaut.processing.group=com.example + + + micronaut.processing.module=micronaut-kt-app + + + + + + compile + + compile + + + + ${project.basedir}/src/main/kotlin + + + + + test-kapt + + test-kapt + + + + ${project.basedir}/src/test/kotlin + + + + io.micronaut + micronaut-inject-java + ${micronaut.version} + + + io.micronaut + micronaut-graal + ${micronaut.version} + + + + + + test-compile + + test-compile + + + + ${project.basedir}/src/test/kotlin + + ${project.basedir}/target/generated-sources/kapt/test + + + + + + + + org.jetbrains.kotlin + kotlin-maven-allopen + ${kotlin.version} + + + + + org.apache.maven.plugins + maven-compiler-plugin + + none + ${java.version} + ${java.version} + + + + default-compile + none + + + default-testCompile + none + + + java-compile + compile + + compile + + + + java-test-compile + test-compile + + testCompile + + + + + + + diff --git a/nx-maven/micronaut/micronaut-kt-app/project.json b/nx-maven/micronaut/micronaut-kt-app/project.json new file mode 100644 index 0000000..8d0e4b0 --- /dev/null +++ b/nx-maven/micronaut/micronaut-kt-app/project.json @@ -0,0 +1,51 @@ +{ + "name": "micronaut-kt-app", + "$schema": "../../../node_modules/nx/schemas/project-schema.json", + "projectType": "application", + "sourceRoot": "./nx-maven/micronaut/micronaut-kt-app/src", + "targets": { + "build": { + "executor": "@jnxplus/nx-maven:run-task", + "outputs": ["{projectRoot}/target", "{projectRoot}/.flattened-pom.xml"], + "options": { + "task": "compile -DskipTests=true" + } + }, + "build-image": { + "executor": "@jnxplus/nx-maven:run-task", + "options": { + "task": "package -Dpackaging=docker" + } + }, + "serve": { + "executor": "@jnxplus/nx-maven:run-task", + "options": { + "task": "mn:run", + "keepItRunning": true + }, + "dependsOn": ["build"] + }, + "test": { + "executor": "@jnxplus/nx-maven:run-task", + "options": { + "task": "test" + }, + "dependsOn": ["build"] + }, + "ktlint": { + "executor": "@jnxplus/nx-maven:run-task", + "options": { + "task": "antrun:run@ktlint" + }, + "dependsOn": ["^build"] + }, + "ktlint-format": { + "executor": "@jnxplus/nx-maven:run-task", + "options": { + "task": "antrun:run@ktlint-format" + }, + "dependsOn": ["^build"] + } + }, + "tags": [] +} diff --git a/nx-maven/micronaut/micronaut-kt-app/src/main/kotlin/com/example/micronaut/micronautktapp/Application.kt b/nx-maven/micronaut/micronaut-kt-app/src/main/kotlin/com/example/micronaut/micronautktapp/Application.kt new file mode 100644 index 0000000..58e0e1c --- /dev/null +++ b/nx-maven/micronaut/micronaut-kt-app/src/main/kotlin/com/example/micronaut/micronautktapp/Application.kt @@ -0,0 +1,7 @@ +package com.example.micronaut.micronautktapp + +import io.micronaut.runtime.Micronaut.run + +fun main(args: Array) { + run(*args) +} diff --git a/nx-maven/micronaut/micronaut-kt-app/src/main/kotlin/com/example/micronaut/micronautktapp/HelloController.kt b/nx-maven/micronaut/micronaut-kt-app/src/main/kotlin/com/example/micronaut/micronautktapp/HelloController.kt new file mode 100644 index 0000000..06c92cb --- /dev/null +++ b/nx-maven/micronaut/micronaut-kt-app/src/main/kotlin/com/example/micronaut/micronautktapp/HelloController.kt @@ -0,0 +1,17 @@ +package com.example.micronaut.micronautktapp + +import com.example.micronaut.micronautktlib.HelloService +import io.micronaut.http.MediaType +import io.micronaut.http.annotation.Controller +import io.micronaut.http.annotation.Get +import io.micronaut.http.annotation.Produces +import jakarta.inject.Inject + +@Controller("/hello") +class HelloController( + @Inject val helloService: HelloService, +) { + @Get + @Produces(MediaType.TEXT_PLAIN) + fun index() = helloService.greeting() +} diff --git a/nx-maven/micronaut/micronaut-kt-app/src/main/resources/application.properties b/nx-maven/micronaut/micronaut-kt-app/src/main/resources/application.properties new file mode 100644 index 0000000..5c14582 --- /dev/null +++ b/nx-maven/micronaut/micronaut-kt-app/src/main/resources/application.properties @@ -0,0 +1,2 @@ +micronaut.application.name=MicronautMicronautKtApp +netty.default.allocator.max-order=3 diff --git a/nx-maven/micronaut/micronaut-kt-app/src/main/resources/logback.xml b/nx-maven/micronaut/micronaut-kt-app/src/main/resources/logback.xml new file mode 100644 index 0000000..1f90cc3 --- /dev/null +++ b/nx-maven/micronaut/micronaut-kt-app/src/main/resources/logback.xml @@ -0,0 +1,15 @@ + + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + diff --git a/nx-maven/micronaut/micronaut-kt-app/src/test/kotlin/com/example/micronaut/micronautktapp/HelloControllerTest.kt b/nx-maven/micronaut/micronaut-kt-app/src/test/kotlin/com/example/micronaut/micronautktapp/HelloControllerTest.kt new file mode 100644 index 0000000..5e9d7c3 --- /dev/null +++ b/nx-maven/micronaut/micronaut-kt-app/src/test/kotlin/com/example/micronaut/micronautktapp/HelloControllerTest.kt @@ -0,0 +1,22 @@ +package com.example.micronaut.micronautktapp + +import io.micronaut.http.HttpRequest +import io.micronaut.http.client.HttpClient +import io.micronaut.http.client.annotation.Client +import io.micronaut.test.extensions.junit5.annotation.MicronautTest +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertNotNull +import org.junit.jupiter.api.Test + +@MicronautTest +class HelloControllerTest( + @Client("/") val client: HttpClient, +) { + @Test + fun testHello() { + val request: HttpRequest = HttpRequest.GET("/hello") + val body = client.toBlocking().retrieve(request) + assertNotNull(body) + assertEquals("Hello World", body) + } +} diff --git a/nx-maven/micronaut/micronaut-kt-app/src/test/kotlin/com/example/micronaut/micronautktapp/MicronautMicronautKtAppTest.kt b/nx-maven/micronaut/micronaut-kt-app/src/test/kotlin/com/example/micronaut/micronautktapp/MicronautMicronautKtAppTest.kt new file mode 100644 index 0000000..68ac860 --- /dev/null +++ b/nx-maven/micronaut/micronaut-kt-app/src/test/kotlin/com/example/micronaut/micronautktapp/MicronautMicronautKtAppTest.kt @@ -0,0 +1,18 @@ +package com.example.micronaut.micronautktapp + +import io.micronaut.runtime.EmbeddedApplication +import io.micronaut.test.extensions.junit5.annotation.MicronautTest +import jakarta.inject.Inject +import org.junit.jupiter.api.Assertions +import org.junit.jupiter.api.Test + +@MicronautTest +class MicronautMicronautKtAppTest { + @Inject + lateinit var application: EmbeddedApplication<*> + + @Test + fun testItWorks() { + Assertions.assertTrue(application.isRunning) + } +} diff --git a/nx-maven/micronaut/micronaut-kt-app/src/test/resources/application.properties b/nx-maven/micronaut/micronaut-kt-app/src/test/resources/application.properties new file mode 100644 index 0000000..a83491f --- /dev/null +++ b/nx-maven/micronaut/micronaut-kt-app/src/test/resources/application.properties @@ -0,0 +1,2 @@ +micronaut.server.port=-1 + diff --git a/nx-maven/micronaut/micronaut-kt-lib/pom.xml b/nx-maven/micronaut/micronaut-kt-lib/pom.xml new file mode 100644 index 0000000..275d2c9 --- /dev/null +++ b/nx-maven/micronaut/micronaut-kt-lib/pom.xml @@ -0,0 +1,201 @@ + + + 4.0.0 + micronaut-kt-lib + micronaut-kt-lib + This project was generated with nx-maven + + + com.example + micronaut-parent-project + ${revision} + ../micronaut-parent-project/pom.xml + + + + + central + https://repo.maven.apache.org/maven2 + + + + + + io.micronaut + micronaut-inject-java + + + + org.jetbrains.kotlin + kotlin-reflect + ${kotlin.version} + compile + + + org.jetbrains.kotlin + kotlin-stdlib-jdk8 + ${kotlin.version} + compile + + + + io.micronaut.test + micronaut-test-junit5 + test + + + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-engine + test + + + + + + + kotlin-maven-plugin + org.jetbrains.kotlin + ${kotlin.version} + + ${java.version} + + all-open + + + + + + + + kapt + + kapt + + + + ${project.basedir}/src/main/kotlin + + + + io.micronaut + micronaut-inject-java + ${micronaut.core.version} + + + io.micronaut + micronaut-graal + ${micronaut.core.version} + + + + + micronaut.processing.group=com.example + + + micronaut.processing.module=demo + + + + + + compile + + compile + + + + ${project.basedir}/src/main/kotlin + + + + + test-kapt + + test-kapt + + + + ${project.basedir}/src/test/kotlin + + + + io.micronaut + micronaut-inject-java + ${micronaut.core.version} + + + io.micronaut + micronaut-graal + ${micronaut.core.version} + + + + + + test-compile + + test-compile + + + + ${project.basedir}/src/test/kotlin + + ${project.basedir}/target/generated-sources/kapt/test + + + + + + + + org.jetbrains.kotlin + kotlin-maven-allopen + ${kotlin.version} + + + + + org.apache.maven.plugins + maven-compiler-plugin + + none + ${java.version} + ${java.version} + + + + default-compile + none + + + default-testCompile + none + + + java-compile + compile + + compile + + + + java-test-compile + test-compile + + testCompile + + + + + + + diff --git a/nx-maven/micronaut/micronaut-kt-lib/project.json b/nx-maven/micronaut/micronaut-kt-lib/project.json new file mode 100644 index 0000000..674f677 --- /dev/null +++ b/nx-maven/micronaut/micronaut-kt-lib/project.json @@ -0,0 +1,38 @@ +{ + "name": "micronaut-kt-lib", + "$schema": "../../../node_modules/nx/schemas/project-schema.json", + "projectType": "library", + "sourceRoot": "./nx-maven/micronaut/micronaut-kt-lib/src", + "targets": { + "build": { + "executor": "@jnxplus/nx-maven:run-task", + "outputs": [ + "{projectRoot}/target", + "{options.outputDirLocalRepo}", + "{projectRoot}/.flattened-pom.xml" + ], + "options": { + "task": "install -DskipTests=true" + } + }, + "test": { + "executor": "@jnxplus/nx-maven:run-task", + "options": { + "task": "test" + } + }, + "ktlint": { + "executor": "@jnxplus/nx-maven:run-task", + "options": { + "task": "antrun:run@ktlint" + } + }, + "ktlint-format": { + "executor": "@jnxplus/nx-maven:run-task", + "options": { + "task": "antrun:run@ktlint-format" + } + } + }, + "tags": [] +} diff --git a/nx-maven/micronaut/micronaut-kt-lib/src/main/kotlin/com/example/micronaut/micronautktlib/HelloService.kt b/nx-maven/micronaut/micronaut-kt-lib/src/main/kotlin/com/example/micronaut/micronautktlib/HelloService.kt new file mode 100644 index 0000000..9652190 --- /dev/null +++ b/nx-maven/micronaut/micronaut-kt-lib/src/main/kotlin/com/example/micronaut/micronautktlib/HelloService.kt @@ -0,0 +1,10 @@ +package com.example.micronaut.micronautktlib + +import jakarta.inject.Singleton + +@Singleton +class HelloService { + fun greeting(): String { + return "Hello World" + } +} diff --git a/nx-maven/micronaut/micronaut-kt-lib/src/test/kotlin/com/example/micronaut/micronautktlib/HelloServiceTest.kt b/nx-maven/micronaut/micronaut-kt-lib/src/test/kotlin/com/example/micronaut/micronautktlib/HelloServiceTest.kt new file mode 100644 index 0000000..1c5dad2 --- /dev/null +++ b/nx-maven/micronaut/micronaut-kt-lib/src/test/kotlin/com/example/micronaut/micronautktlib/HelloServiceTest.kt @@ -0,0 +1,18 @@ +package com.example.micronaut.micronautktlib + +import io.micronaut.test.extensions.junit5.annotation.MicronautTest +import jakarta.inject.Inject +import org.junit.jupiter.api.Assertions +import org.junit.jupiter.api.Test + +@MicronautTest +class HelloServiceTest { + @Inject + lateinit var service: HelloService + + @Test + fun `Should return Hello World`() { + println(">> Should return Hello World") + Assertions.assertTrue(service.greeting().contains("Hello World")) + } +} diff --git a/nx-maven/pom.xml b/nx-maven/pom.xml index 78df861..a5f236e 100644 --- a/nx-maven/pom.xml +++ b/nx-maven/pom.xml @@ -136,6 +136,8 @@ micronaut/micronaut-parent-project micronaut/micronaut-app micronaut/micronaut-lib + micronaut/micronaut-kt-app + micronaut/micronaut-kt-lib quarkus/quarkus-parent-project quarkus/quarkus-app quarkus/quarkus-lib