-
-
Notifications
You must be signed in to change notification settings - Fork 971
fix: configure Micronaut annotation processor and CLASSIC boot loader automatically #15411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jamesfredley
wants to merge
16
commits into
7.0.x
Choose a base branch
from
micronaut-fixes-2
base: 7.0.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+663
−13
Open
Changes from 11 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
32ac386
prevent duplicate loading of micronaut beans & fix bootJar task
jdaugherty 37f5114
Merge remote-tracking branch 'origin/7.0.x' into micronaut-fixes
jamesfredley 6fd254b
fix: configure Micronaut annotation processor and CLASSIC loader in G…
jamesfredley 19fa41e
fix: add bootWar CLASSIC loader to Forge-generated build.gradle
jamesfredley beff44a
chore: add Apache license header to GrailsMicronautValidator
jamesfredley 888fa45
test: add integration tests for Micronaut bean type registration
jamesfredley 6d4dfc9
docs: document Micronaut annotation processor and CLASSIC loader in u…
jamesfredley fbf50a2
fix: exclude Spring Boot DevTools for Micronaut apps in Forge
jamesfredley b3062c6
test: add bean duplication and cross-context identity tests for Micro…
jamesfredley b04d6d5
fix: address review feedback on test correctness and documentation
jamesfredley 4e9d6b9
refactor: extract JavaMessageProvider to its own file
jamesfredley ae7747a
fix: remove annotation processor auto-config and add declarative @Cli…
jamesfredley e6e202a
Merge branch '7.0.x' into micronaut-fixes-2
jamesfredley 782b950
test: invoke declarative @Client through load balancing path with ers…
jamesfredley 03d1a51
fix: restore Micronaut annotation processor auto-config in GrailsGrad…
jamesfredley 79cdfc1
fix: move Micronaut annotation processor config to test apps with Jav…
jamesfredley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...forge-core/src/main/java/org/grails/forge/feature/micronaut/GrailsMicronautValidator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
| package org.grails.forge.feature.micronaut; | ||
|
|
||
| import jakarta.inject.Singleton; | ||
| import org.grails.forge.application.ApplicationType; | ||
| import org.grails.forge.feature.Feature; | ||
| import org.grails.forge.feature.reloading.SpringBootDevTools; | ||
| import org.grails.forge.feature.validation.FeatureValidator; | ||
| import org.grails.forge.options.Options; | ||
|
|
||
| import java.util.Set; | ||
|
|
||
| @Singleton | ||
| public class GrailsMicronautValidator implements FeatureValidator { | ||
| @Override | ||
| public void validatePreProcessing(Options options, ApplicationType applicationType, Set<Feature> features) { | ||
| if (features.stream().anyMatch(f -> f instanceof GrailsMicronaut)) { | ||
| if (features.stream().anyMatch(f -> (f instanceof SpringBootDevTools))) { | ||
| // See: https://github.com/micronaut-projects/micronaut-spring/issues/769 | ||
| throw new IllegalArgumentException("Spring Boot Dev Tools are not supported with Grails Micronaut"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void validatePostProcessing(Options options, ApplicationType applicationType, Set<Feature> features) { | ||
|
|
||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,6 +48,8 @@ spring: | |
| management: | ||
| endpoints: | ||
| enabled-by-default: false | ||
| app: | ||
| name: test-micronaut-app | ||
|
|
||
| --- | ||
| grails: | ||
|
|
||
53 changes: 53 additions & 0 deletions
53
...s-test-examples/micronaut/grails-app/controllers/micronaut/MicronautTestController.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
| package micronaut | ||
|
|
||
| import bean.injection.AppConfig | ||
| import bean.injection.FactoryCreatedService | ||
| import bean.injection.JavaSingletonService | ||
| import bean.injection.NamedService | ||
| import grails.converters.JSON | ||
| import groovy.transform.CompileStatic | ||
|
|
||
| import org.springframework.beans.factory.annotation.Autowired | ||
|
|
||
| @CompileStatic | ||
| class MicronautTestController { | ||
|
|
||
| @Autowired | ||
| JavaSingletonService javaSingletonService | ||
|
|
||
| @Autowired | ||
| FactoryCreatedService factoryCreatedService | ||
|
|
||
| @Autowired | ||
| AppConfig appConfig | ||
|
|
||
| @Autowired | ||
| NamedService namedService | ||
|
|
||
| def index() { | ||
| render([ | ||
| javaMessage: javaSingletonService.message, | ||
| factoryName: factoryCreatedService.name, | ||
| appName: appConfig.name, | ||
| namedService: namedService.name | ||
| ] as JSON) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
...mples/micronaut/src/integration-test/groovy/micronaut/MicronautBeanDuplicationSpec.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
| package micronaut | ||
|
|
||
| import bean.injection.AppConfig | ||
| import bean.injection.FactoryCreatedService | ||
| import bean.injection.JavaSingletonService | ||
| import bean.injection.NamedService | ||
|
|
||
| import grails.testing.mixin.integration.Integration | ||
| import io.micronaut.context.ApplicationContext as MicronautApplicationContext | ||
| import org.springframework.beans.factory.annotation.Autowired | ||
| import org.springframework.context.ApplicationContext as SpringApplicationContext | ||
| import org.springframework.context.ApplicationContextAware | ||
| import spock.lang.Specification | ||
|
|
||
| /** | ||
| * Integration tests verifying no bean duplication occurs between Spring and Micronaut contexts. | ||
| * | ||
| * When micronaut-spring bridges Micronaut beans into Spring, each bean should appear | ||
| * exactly once in the Spring context (not duplicated). Similarly, Micronaut beans | ||
| * should maintain correct counts in the Micronaut context. | ||
| */ | ||
| @Integration | ||
| class MicronautBeanDuplicationSpec extends Specification implements ApplicationContextAware { | ||
|
|
||
| @Autowired | ||
| MicronautApplicationContext micronautContext | ||
|
|
||
| SpringApplicationContext springContext | ||
|
|
||
| void setApplicationContext(SpringApplicationContext applicationContext) { | ||
| this.springContext = applicationContext | ||
| } | ||
|
|
||
| void "Java @Singleton bean appears exactly once in Spring context"() { | ||
| when: | ||
| def beans = springContext.getBeansOfType(JavaSingletonService) | ||
|
|
||
| then: "only one instance is registered, not duplicated by the bridge" | ||
| beans.size() == 1 | ||
| } | ||
|
|
||
| void "@Factory/@Bean created bean appears exactly once in Spring context"() { | ||
| when: | ||
| def beans = springContext.getBeansOfType(FactoryCreatedService) | ||
|
|
||
| then: "only one instance is registered" | ||
| beans.size() == 1 | ||
| } | ||
|
|
||
| void "@ConfigurationProperties bean appears exactly once in Spring context"() { | ||
| when: | ||
| def beans = springContext.getBeansOfType(AppConfig) | ||
|
|
||
| then: "only one instance is registered" | ||
| beans.size() == 1 | ||
| } | ||
|
|
||
| void "NamedService implementations appear exactly 4 times in Spring context"() { | ||
| when: | ||
| def beans = springContext.getBeansOfType(NamedService) | ||
|
|
||
| then: "4 implementations, not 8 from duplication" | ||
| beans.size() == 4 | ||
| } | ||
|
|
||
| void "Micronaut context has exactly 4 NamedService implementations"() { | ||
| when: | ||
| def beans = micronautContext.getBeansOfType(NamedService) | ||
|
|
||
| then: | ||
| beans.size() == 4 | ||
| } | ||
|
|
||
| void "Grails service appears exactly once in Spring context"() { | ||
| when: | ||
| def beans = springContext.getBeansOfType(BeanInjectionService) | ||
|
|
||
| then: "Grails artefact not duplicated by Micronaut bridge" | ||
| beans.size() == 1 | ||
| } | ||
|
|
||
| void "bridged Micronaut bean in Spring is same instance as in Micronaut context"() { | ||
| when: | ||
| def fromSpring = springContext.getBean(JavaSingletonService) | ||
| def fromMicronaut = micronautContext.getBean(JavaSingletonService) | ||
|
|
||
| then: "bridge shares the same singleton, not a copy" | ||
| fromSpring.is(fromMicronaut) | ||
| } | ||
|
|
||
| void "factory-created bean in Spring is same instance as in Micronaut context"() { | ||
| when: | ||
| def fromSpring = springContext.getBean(FactoryCreatedService) | ||
| def fromMicronaut = micronautContext.getBean(FactoryCreatedService) | ||
|
|
||
| then: "bridge shares the same singleton" | ||
| fromSpring.is(fromMicronaut) | ||
| } | ||
|
|
||
| void "@ConfigurationProperties bean in Spring is same instance as in Micronaut context"() { | ||
| when: | ||
| def fromSpring = springContext.getBean(AppConfig) | ||
| def fromMicronaut = micronautContext.getBean(AppConfig) | ||
|
|
||
| then: "bridge shares the same singleton" | ||
| fromSpring.is(fromMicronaut) | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The annotation processors are incompatible with groovy incremental compilation and have previously never been configured. I'd argue we shouldn't configure them and document it so that if someone wants it for java, they can have it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Removed the auto-configured annotation processors. Added a comment in the plugin noting the incompatibility with Groovy incremental compilation and pointing to the docs for manual setup.
The micronaut test example now explicitly configures the annotationProcessor deps in its own build.gradle since it has Java sources (
JavaSingletonService.java). All 33 integration tests pass.