Skip to content

Instantly share code, notes, and snippets.

@sdelamo
Last active February 16, 2023 11:39
Show Gist options
  • Save sdelamo/858097b4a96848937221175eaee4b384 to your computer and use it in GitHub Desktop.
Save sdelamo/858097b4a96848937221175eaee4b384 to your computer and use it in GitHub Desktop.
Micronaut Framework 4 Milestone 1 Blog post

Micronaut 4.0.0 Milestone 1

Baseline Java 17

Micronaut Framework 4.0 sets a baseline for Java to 17.

Apache Groovy 4

Micronaut Framework 4.x supports Apache Groovy 4.0

Kotlin 1.8

Micronaut Framework 4.0 supports Kotlin 1.8.0.

Virtual Threads Support

Since Java 19, the JVM includes experimental support for virtual threads project loom. As it is a preview feature, you need to pass --enable-preview as a JVM parameter to enable it.

The Micronaut framework will detect virtual thread support and use it for the executor named blocking if available. If virtual threads are not supported, this executor will be aliased to the io thread pool.

To use the blocking executor, simply mark e.g. a controller with ExecuteOn:

@Controller("/hello")
class HelloWorldController {

    @ExecuteOn(TaskExecutors.BLOCKING)
    @Produces(MediaType.TEXT_PLAIN)
    @Get("/world")
    String index() {
        return "Hello World";
    }
}

Kotlin support via KAPT or KSP

Micronaut Framework has offered support for Kotlin via Kapt.

With version 4.0, Micronaut Framework supports Kotlin also via Kotlin Symbol Processing (KSP) API.

Please note that kapt is in maintenance mode. Micronaut Kotlin users should move to our KSP support.

kapt is in maintenance mode. We are keeping it up-to-date with recent Kotlin and Java releases but have no plans to implement new features.

Java NET HTTP CLIENT

Since the Micronaut Framework 4.0, you can use two implementation of the Micronaut HTTP Client. The current implementation based on Netty and a new implementation based on Java HTTP Client(JEP 321).

To use the new implementation, add the following dependency.

To you Gradle build:

dependencies {
    ...
    implementation("io.micronaut:micronaut-http-client-javanet")
}

Or to your Maven build:

    ...
    <dependency>
      <groupId>io.micronaut</groupId>
      <artifactId>micronaut-http-client-javanet</artifactId>
      <scope>compile</scope>
    </dependency>
  </dependencies>

Core Improvements

TODO

  • Injection of Maps
  • Support arbitrary nesting of EachProperty/ConfigurationProperties beans
  • Connection Pooling and HTTP/2
  • Support custom HTTP status codes
  • Conversion Service
  • Performance Improvements

Bean Listeners are loaded lazily.

Validation Changes

TODO

Vetoed annotation

TODO

Logging

Logback 1.4.5 and SLF4J 2.0.4

Jakarta Migration

TODO

Breaking Changes

micronaut-runtime does not expose io.micronaut:micronaut-jackson-databind anymore.. You have to choose whether to use Micronaut Serialization or Jackson Databind.

micronaut-core does not expose SnakeYAML as transitive dependency anymore.. To continue to use YAML for application configuration, add the org.yam:snakeyaml dependency to your application.

Disable Cloud Environment deduction by default

TODO

Lighter Runtime

The micronaut-runtime module has been split into separate modules depending on the application's use case:

Micronaut Discovery Core

The base service discovery features are now in a separate module. If your application listens for events such as ServiceReadyEvent or api:discovery.heartbeat.HeartBeatEvent[] add the following dependency.

To you Gradle build:

dependencies {
    ...
    implementation("io.micronaut:micronaut-discovery")
}

Or to your Maven build:

    ...
    <dependency>
      <groupId>io.micronaut</groupId>
      <artifactId>micronaut-discovery</artifactId>
      <scope>compile</scope>
    </dependency>
  </dependencies>

dependency::[]

Micronaut Retry

The retry implementation including annotations such as Retryable is now a separate module that can be optionally included in a Micronaut application.

In addition, since micronaut-retry is now optional declarative clients annotated with ann:http.client.annotation.Client[] no longer invoke fallbacks by default. To restore the previous behaviour add micronaut-retry to your classpath and annotate any declarative clients with @Recoverable.

To use the Retry functionality, add the following dependency.

To you Gradle build:

dependencies {
    ...
    implementation("io.micronaut:micronaut-retry")
}

Or to your Maven build:

    ...
    <dependency>
      <groupId>io.micronaut</groupId>
      <artifactId>micronaut-retry</artifactId>
      <scope>compile</scope>
    </dependency>
  </dependencies>

Websocket not exposed transitively

io.micronaut:micronaut-http-server no longer exposes micrnoaut-websocket transitively. If your application uses annotations such as @ServerWebSocket, add the micronaut-websocket dependency.

To you Gradle build:

dependencies {
    ...
    implementation("io.micronaut:micronaut-websocket")
}

Or to your Maven build:

    ...
    <dependency>
      <groupId>io.micronaut</groupId>
      <artifactId>micronaut-websocket</artifactId>
      <scope>compile</scope>
    </dependency>
  </dependencies>

Session Module

Micronaut Session has been moved to its own module. If you use the HTTP session module, change the maven coordinates from io.micronaut:micronaut-session to io.micronaut.session:micronaut-session.

micronaut-http-server-netty module no longer depends on micronaut-discovery, micronaut-health and micronaut-websocket

TODO

CORE BOM

bom -> core-bom

Platform Module

BOM

Other Modules extracted from CORE

TODO

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment