Skip to content

Commit

Permalink
add gradle micronaut projects (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
khalilou88 authored Jan 13, 2024
1 parent 9075b0a commit 148d364
Show file tree
Hide file tree
Showing 31 changed files with 560 additions and 5 deletions.
4 changes: 4 additions & 0 deletions nx-gradle/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ plugins {
id("io.quarkus") apply false
kotlin("jvm") apply false
kotlin("plugin.allopen") apply false
id("com.github.johnrengelman.shadow") apply false
id("io.micronaut.application") apply false
id("io.micronaut.aot") apply false
id("com.google.devtools.ksp") apply false
}
3 changes: 3 additions & 0 deletions nx-gradle/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ kotlinVersion=1.9.20
springBootVersion=3.2.0
springDependencyManagementVersion=1.1.4
quarkusVersion=3.5.3
micronautVersion=4.2.0
kspVersion=1.9.20-1.0.14
shadowVersion=8.1.1
jnxplusGradlePluginVersion=0.2.2


Expand Down
54 changes: 54 additions & 0 deletions nx-gradle/micronaut/g-m-app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
val javaVersion: String by project

plugins {
id("com.github.johnrengelman.shadow")
id("io.micronaut.application")
id("io.micronaut.aot")
}

version = "0.0.1-SNAPSHOT"
group = "com.example"

repositories {
mavenCentral()
}

dependencies {
annotationProcessor("io.micronaut.serde:micronaut-serde-processor")
implementation("io.micronaut.serde:micronaut-serde-jackson")
runtimeOnly("ch.qos.logback:logback-classic")
testImplementation("io.micronaut:micronaut-http-client")
implementation(project(":micronaut:g-m-lib"))
}


application {
mainClass.set("com.example.gmapp.Application")
}

java {
sourceCompatibility = JavaVersion.toVersion(javaVersion)
targetCompatibility = JavaVersion.toVersion(javaVersion)
}

graalvmNative.toolchainDetection.set(false)

micronaut {
runtime("netty")
testRuntime("junit5")
processing {
incremental(true)
annotations("com.example.gmapp.*")
}
aot {
// Please review carefully the optimizations enabled below
// Check https://micronaut-projects.github.io/micronaut-aot/latest/guide/ for more details
optimizeServiceLoading.set(false)
convertYamlToJava.set(false)
precomputeOperations.set(true)
cacheEnvironment.set(true)
optimizeClassLoading.set(true)
deduceEnvironment.set(true)
optimizeNetty.set(true)
}
}
35 changes: 35 additions & 0 deletions nx-gradle/micronaut/g-m-app/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "g-m-app",
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"sourceRoot": "./nx-gradle/micronaut/g-m-app/src",
"targets": {
"build": {
"executor": "@jnxplus/nx-gradle:run-task",
"outputs": ["{projectRoot}/build"],
"options": {
"task": "build"
}
},
"build-image": {
"executor": "@jnxplus/nx-gradle:run-task",
"options": {
"task": "dockerBuild"
}
},
"serve": {
"executor": "@jnxplus/nx-gradle:run-task",
"options": {
"task": "run",
"keepItRunning": true
}
},
"test": {
"executor": "@jnxplus/nx-gradle:run-task",
"options": {
"task": "test"
}
}
},
"tags": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.gmapp;

import io.micronaut.runtime.Micronaut;

public class Application {

public static void main(String[] args) {
Micronaut.run(Application.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.example.gmapp;

import com.example.gmlib.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")
public class HelloController {

@Inject
private HelloService helloService;

@Get
@Produces(MediaType.TEXT_PLAIN)
public String index() {
return helloService.greeting();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
micronaut.application.name=GMApp
netty.default.allocator.max-order=3
15 changes: 15 additions & 0 deletions nx-gradle/micronaut/g-m-app/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>
%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
</pattern>
</encoder>
</appender>

<root level="info">
<appender-ref ref="STDOUT" />
</root>
</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.example.gmapp;

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 GMAppTest {

@Inject
EmbeddedApplication<?> application;

@Test
void testItWorks() {
Assertions.assertTrue(application.isRunning());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.example.gmapp;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

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 jakarta.inject.Inject;
import org.junit.jupiter.api.Test;

@MicronautTest
public class HelloControllerTest {

@Inject
@Client("/")
HttpClient client;

@Test
public void testHello() {
HttpRequest<String> request = HttpRequest.GET("/hello");
String body = client.toBlocking().retrieve(request);

assertNotNull(body);
assertEquals("Hello World", body);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
micronaut.server.port=-1

64 changes: 64 additions & 0 deletions nx-gradle/micronaut/g-m-kt-app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

val javaVersion: String by project
val kotlinVersion: String by project

plugins {
id("org.jetbrains.kotlin.jvm")
id("org.jetbrains.kotlin.plugin.allopen")
id("com.google.devtools.ksp")
id("com.github.johnrengelman.shadow")
id("io.micronaut.application")
id("io.micronaut.aot")
}

version = "0.0.1-SNAPSHOT"
group = "com.example"


repositories {
mavenCentral()
}

dependencies {
ksp("io.micronaut.serde:micronaut-serde-processor")
implementation("io.micronaut.kotlin:micronaut-kotlin-runtime")
implementation("io.micronaut.serde:micronaut-serde-jackson")
implementation("org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlinVersion}")
runtimeOnly("ch.qos.logback:logback-classic")
runtimeOnly("com.fasterxml.jackson.module:jackson-module-kotlin")
testImplementation("io.micronaut:micronaut-http-client")
runtimeOnly("org.yaml:snakeyaml")
implementation(project(":micronaut:g-m-kt-lib"))
}

application {
mainClass.set("com.example.gmktapp.ApplicationKt")
}

java {
sourceCompatibility = JavaVersion.toVersion(javaVersion)
}

graalvmNative.toolchainDetection.set(false)

micronaut {
runtime("netty")
testRuntime("junit5")
processing {
incremental(true)
annotations("com.example.gmktapp.*")
}
aot {
// Please review carefully the optimizations enabled below
// Check https://micronaut-projects.github.io/micronaut-aot/latest/guide/ for more details
optimizeServiceLoading.set(false)
convertYamlToJava.set(false)
precomputeOperations.set(true)
cacheEnvironment.set(true)
optimizeClassLoading.set(true)
deduceEnvironment.set(true)
optimizeNetty.set(true)
}
}
35 changes: 35 additions & 0 deletions nx-gradle/micronaut/g-m-kt-app/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "g-m-kt-app",
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"sourceRoot": "./nx-gradle/micronaut/g-m-kt-app/src",
"targets": {
"build": {
"executor": "@jnxplus/nx-gradle:run-task",
"outputs": ["{projectRoot}/build"],
"options": {
"task": "build"
}
},
"build-image": {
"executor": "@jnxplus/nx-gradle:run-task",
"options": {
"task": "dockerBuild"
}
},
"serve": {
"executor": "@jnxplus/nx-gradle:run-task",
"options": {
"task": "run",
"keepItRunning": true
}
},
"test": {
"executor": "@jnxplus/nx-gradle:run-task",
"options": {
"task": "test"
}
}
},
"tags": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.gmktapp

import io.micronaut.runtime.Micronaut.run
fun main(args: Array<String>) {
run(*args)
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.example.gmktapp

import com.example.gmktlib.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()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
micronaut:
application:
name: GMKtApp
netty:
default:
allocator:
max-order: 3
15 changes: 15 additions & 0 deletions nx-gradle/micronaut/g-m-kt-app/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>
%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
</pattern>
</encoder>
</appender>

<root level="info">
<appender-ref ref="STDOUT" />
</root>
</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.example.gmktapp

import io.micronaut.runtime.EmbeddedApplication
import io.micronaut.test.extensions.junit5.annotation.MicronautTest
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import jakarta.inject.Inject

@MicronautTest
class GMKtAppTest {

@Inject
lateinit var application: EmbeddedApplication<*>

@Test
fun testItWorks() {
Assertions.assertTrue(application.isRunning)
}

}
Loading

0 comments on commit 148d364

Please sign in to comment.