////
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
////

=== Micronaut Integration

Grails supports using the Micronaut framework via the `grails-micronaut` plugin. The `grails-micronaut` plugin uses the https://micronaut-projects.github.io/micronaut-spring/latest/guide/#springBootStarter[Micronaut Spring Boot Starter] so that both the Micronaut Application Context & Grails Application Context exist side by side.

To enable Micronaut in your Grails application, two steps must be completed:

. Apply `grails-micronaut-bom` as `enforcedPlatform` (instead of `grails-bom`).
. Add the `grails-micronaut` library.

Here's an example build file:

[source,groovy]
.build.gradle
----
dependencies {
    // enforcedPlatform is required: it forces grails-bom-managed versions over the
    // versions declared by the Micronaut platform (e.g. javaparser-core, Groovy 4),
    // preventing binary incompatibilities at runtime.
    implementation enforcedPlatform("org.apache.grails:grails-micronaut-bom:$grailsVersion")

    implementation 'org.apache.grails:grails-micronaut'
}
----

The `grails-micronaut-bom` layers Micronaut-specific dependency overrides on top of `grails-bom` and pins the `io.micronaut.platform:micronaut-platform` version it was built against. Applying it as `enforcedPlatform` makes all of its constraints strictly versioned so that no transitive dependency (including Micronaut's own platform) can override them — there is no need to set a `micronautPlatformVersion` Gradle property. See link:{versionsRef}Grails%20BOM%20Micronaut.html[Grails Micronaut BOM Dependencies] for the full list of managed versions.

When the `grails-micronaut` plugin is present, the Grails Gradle plugin will automatically apply the required annotation processors to your project and validate that `grails-micronaut-bom` is applied as `enforcedPlatform`. The validation fails the build at configuration time with an actionable error if the BOM is missing or applied as plain `platform(...)`.

==== Disabling the Micronaut Auto-Setup

The Micronaut auto-setup defaults to on. If a project deliberately deviates from the recommended setup, it can be disabled via the `grails` extension:

[source,groovy]
.build.gradle
----
grails {
    micronautAutoSetup = false // not recommended — also skips the bootJar/bootWar CLASSIC loader configuration
}
----

WARNING: Disabling auto-setup is rarely appropriate. Without `enforcedPlatform`, Gradle's default conflict resolution allows the Micronaut platform to silently override grails-bom-managed versions of libraries such as Groovy and `javaparser-core`, leading to binary incompatibilities at runtime. The CLASSIC loader configuration that auto-setup provides is also required for `java -jar` compatibility with the Micronaut-Spring integration.

==== Generated Applications

Applications generated by https://forge.grails.org/[Grails Forge] with the Micronaut feature selected automatically use `enforcedPlatform("org.apache.grails:grails-micronaut-bom:$grailsVersion")` and require no further setup.