Closed mraible closed 2 years ago
I can confirm that this is reproducible when using AOT, but not when not using it.
When it doesn't work, the message in Surefire report is this:
Test is not bean. Either the test does not satisfy requirements defined by @Requires or annotation processing is not enabled. If the latter ensure annotation processing is enabled in your IDE
Surely the reason is something else. Annotation processors are configured. The target/test-classes
directory is the same in both cases:
target/test-classes
├── META-INF
│ └── services
│ └── io.micronaut.inject.BeanDefinitionReference
└── com
└── okta
└── rest
├── $App2Test$Definition$Exec.class
├── $App2Test$Definition$Reference.class
├── $App2Test$Definition.class
└── App2Test.class
In both cases, the content of target/test-classes/META-INF/services/io.micronaut.inject.BeanDefinitionReference
is the same:
com.okta.rest.$App2Test$Definition$Reference
@melix do you think that the AOT configuration that we provide by default could be causing this? For reference, it's this:
# AOT configuration properties for jar packaging
# Please review carefully the optimizations enabled below
# Check https://micronaut-projects.github.io/micronaut-aot/latest/guide/ for more details
# Caches environment property values: environment properties will be deemed immutable after application startup.
cached.environment.enabled=true
# Precomputes Micronaut configuration property keys from the current environment variables
precompute.environment.properties.enabled=true
# Converts YAML configuration files to Java configuration
yaml.to.java.config.enabled=true
# Scans for service types ahead-of-time, avoiding classpath scanning at startup
serviceloading.jit.enabled = true
# Scans reactive types at build time instead of runtime
scan.reactive.types.enabled=true
# Deduces the environment at build time instead of runtime
deduce.environment.enabled=true
# Checks of existence of some types at build time instead of runtime
known.missing.types.enabled=true
# Precomputes property sources at build time
sealed.property.source.enabled=true
# The list of service types to be scanned (comma separated)
service.types=io.micronaut.context.env.PropertySourceLoader,io.micronaut.inject.BeanConfiguration,io.micronaut.inject.BeanDefinitionReference,io.micronaut.http.HttpRequestFactory,io.micronaut.http.HttpResponseFactory,io.micronaut.core.beans.BeanIntrospectionReference
# A list of types that the AOT analyzer needs to check for existence (comma separated)
known.missing.types.list=io.reactivex.Observable,reactor.core.publisher.Flux,kotlinx.coroutines.flow.Flow,io.reactivex.rxjava3.core.Flowable,io.reactivex.rxjava3.core.Observable,io.reactivex.Single,reactor.core.publisher.Mono,io.reactivex.Maybe,io.reactivex.rxjava3.core.Single,io.reactivex.rxjava3.core.Maybe,io.reactivex.Completable,io.reactivex.rxjava3.core.Completable,io.methvin.watchservice.MacOSXListeningWatchService,io.micronaut.core.async.publisher.CompletableFuturePublisher,io.micronaut.core.async.publisher.Publishers.JustPublisher,io.micronaut.core.async.subscriber.Completable
Ok, disabling serviceloading.jit.enabled
makes it work again.
Is it because the service.types
list is wrong?
The service type list is correct. I think the problem is different: if AOT is used, then the list of services is hardcoded. Because it happens at compile time after the main source sets are processed, then we only find the production beans. Therefore the test beans are not loaded. Note that it's a difference between Gradle and Maven here: with Gradle the tests are not executed with AOT optimizations, there are always executed without. I'm not sure what we can do here :/
I guess one way to fix this would be to run AOT with the production and test classes, but the problem is that you certainly don't want to have the test classes referenced in your production code :thinking:
Ok, I see.
I'll see if I can skip the AOT analysis if the test
phase is being run.
For some reason
mvn test
skips the unit test in a new Micronaut project.I created the project with:
Then, I replaced the
application.yml
with the following contents:The test is as follows: