sdelamo commented on code in PR #14953:
URL: https://github.com/apache/grails-core/pull/14953#discussion_r2259256014
##########
grails-gradle/plugins/src/main/groovy/org/grails/gradle/plugin/core/GrailsGradlePlugin.groovy:
##########
@@ -386,17 +381,34 @@ class GrailsGradlePlugin extends GroovyPlugin {
@CompileStatic
protected void configureMicronaut(Project project) {
- final String micronautVersion = project.properties['micronautVersion']
- if (micronautVersion) {
- project.configurations.configureEach({ Configuration configuration
->
- configuration.resolutionStrategy.eachDependency({
DependencyResolveDetails details ->
+ project.afterEvaluate {
+ boolean micronautEnabled =
project.getConfigurations().getByName("implementation").getDependencies().findAll
{ Dependency dep -> dep.group == 'org.apache.grails' && dep.name ==
'grails-micronaut' } as boolean
+ if (!micronautEnabled) {
+ return
+ }
+ project.logger.lifecycle('Micronaut Support Detected for {}',
project.name)
+
+ final String micronautPlatformVersion =
project.properties['micronautPlatformVersion']
+ if (!micronautPlatformVersion) {
+ throw new GradleException("`micronautPlatformVersion` property
must be set to use the Grails Micronaut plugin.")
+ }
+
+ // grails-micronaut exports the platform, but force the version to
the user specified version
+ project.configurations.configureEach{ Configuration configuration
->
+ configuration.resolutionStrategy.eachDependency {
DependencyResolveDetails details ->
String dependencyName = details.requested.name
String group = details.requested.group
- if (group == 'io.micronaut' &&
dependencyName.startsWith('micronaut')) {
- details.useVersion(micronautVersion)
+ if (group == 'io.micronaut' &&
dependencyName.startsWith('micronaut-platform')) {
+ project.logger.info("Forcing Micronaut Platform
version to {}", micronautPlatformVersion)
+ details.useVersion(micronautPlatformVersion)
}
- } as Action<DependencyResolveDetails>)
- } as Action<Configuration>)
+ }
+ }
+
+ project.logger.info('Adding Micronaut annotationProcessor
dependencies to project {}', project.name)
+ project.getDependencies().add('annotationProcessor',
project.dependencies.platform("io.micronaut.platform:micronaut-platform:$micronautPlatformVersion"))
+ project.getDependencies().add('annotationProcessor',
'io.micronaut:micronaut-inject-java')
+ project.getDependencies().add('annotationProcessor',
'jakarta.annotation:jakarta.annotation-api')
Review Comment:
> You will then need to explicitly specify a dependency on a version of the
Jakarta Annotations module that uses the jakarta namespace instead of the javax
namespace (versions 2.0.x and above). This is because the Spring Boot BOM
automatically downgrades this module’s version to one that uses the javax
namespace which is incompatible with Micronaut:
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]