smallrye / smallrye-context-propagation

SmallRye implementation of MicroProfile Context Propagation
Apache License 2.0
30 stars 24 forks source link

Classes not found when upgrading from 2.0.0 to 2.1.0 in Mutiny #440

Closed jponge closed 11 months ago

jponge commented 11 months ago

Upgrading from 2.0.0 to 2.1.0 in Mutiny yields class not found exceptions in the mutiny-smallrye-context-propagation module:

[ERROR] io.smallrye.mutiny.context.MultiContextPropagationTest.testCompletionStage -- Time elapsed: 0.003 s <<< ERROR!
java.lang.NoClassDefFoundError: jakarta/annotation/Priority
    at io.smallrye.config.SmallRyeConfigBuilder$InterceptorWithPriority.getPriority(SmallRyeConfigBuilder.java:597)
    at io.smallrye.config.SmallRyeConfigBuilder$InterceptorWithPriority$1.getPriority(SmallRyeConfigBuilder.java:572)
    at io.smallrye.config.SmallRyeConfigBuilder$InterceptorWithPriority.<init>(SmallRyeConfigBuilder.java:579)
    at io.smallrye.config.SmallRyeConfigBuilder$InterceptorWithPriority.<init>(SmallRyeConfigBuilder.java:559)
    at io.smallrye.config.SmallRyeConfigBuilder.getDefaultInterceptors(SmallRyeConfigBuilder.java:296)
    at io.smallrye.config.SmallRyeConfig$ConfigSources.buildInterceptors(SmallRyeConfig.java:602)
    at io.smallrye.config.SmallRyeConfig$ConfigSources.<init>(SmallRyeConfig.java:545)
    at io.smallrye.config.SmallRyeConfig.<init>(SmallRyeConfig.java:68)
    at io.smallrye.config.SmallRyeConfigBuilder.build(SmallRyeConfigBuilder.java:532)
    at io.smallrye.config.SmallRyeConfigFactory$Default.getConfigFor(SmallRyeConfigFactory.java:59)
    at io.smallrye.config.SmallRyeConfigProviderResolver.getConfig(SmallRyeConfigProviderResolver.java:76)
    at io.smallrye.config.SmallRyeConfigProviderResolver.getConfig(SmallRyeConfigProviderResolver.java:64)
    at org.eclipse.microprofile.config.ConfigProvider.getConfig(ConfigProvider.java:85)
    at io.smallrye.context.impl.DefaultValues.<init>(DefaultValues.java:41)
    at io.smallrye.context.SmallRyeContextManager.<init>(SmallRyeContextManager.java:63)
    at io.smallrye.context.SmallRyeContextManager$Builder.build(SmallRyeContextManager.java:337)
    at io.smallrye.context.SmallRyeContextManagerProvider.getContextManager(SmallRyeContextManagerProvider.java:48)
    at io.smallrye.context.SmallRyeContextManagerProvider.getContextManager(SmallRyeContextManagerProvider.java:37)
    at io.smallrye.context.SmallRyeContextManagerProvider.getManager(SmallRyeContextManagerProvider.java:97)
    at io.smallrye.context.SmallRyeThreadContext.getCurrentThreadContextOrDefaultContexts(SmallRyeThreadContext.java:160)
    at io.smallrye.mutiny.context.DefaultContextPropagationInterceptor.getThreadContext(DefaultContextPropagationInterceptor.java:12)
    at io.smallrye.mutiny.context.BaseContextPropagationInterceptor.decorate(BaseContextPropagationInterceptor.java:33)
    at io.smallrye.mutiny.infrastructure.Infrastructure.decorate(Infrastructure.java:152)
    at io.smallrye.mutiny.groups.MultiCreate.emitter(MultiCreate.java:456)
    at io.smallrye.mutiny.groups.MultiCreate.emitter(MultiCreate.java:408)
    at io.smallrye.mutiny.context.MultiContextPropagationTest.testCompletionStage(MultiContextPropagationTest.java:197)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
    at java.base/java.lang.reflect.Method.invoke(Method.java:578)
    at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:727)
    at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
    at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:156)
    at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:147)
    at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:86)
    at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(InterceptingExecutableInvoker.java:103)
    at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.lambda$invoke$0(InterceptingExecutableInvoker.java:93)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
    at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:92)
    at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:86)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$7(TestMethodTestDescriptor.java:217)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:213)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:138)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:68)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:151)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
    at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
    at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
    at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
    at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
    at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
    at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54)
    at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:147)
    at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:127)
    at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:90)
    at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:55)
    at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:102)
    at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:54)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86)
    at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86)
    at org.apache.maven.surefire.junitplatform.LazyLauncher.execute(LazyLauncher.java:56)
    at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.execute(JUnitPlatformProvider.java:184)
    at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invokeAllTests(JUnitPlatformProvider.java:148)
    at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invoke(JUnitPlatformProvider.java:122)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:385)
    at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:162)
    at org.apache.maven.surefire.booter.ForkedBooter.run(ForkedBooter.java:507)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:495)
Caused by: java.lang.ClassNotFoundException: jakarta.annotation.Priority
    ... 95 more
manovotn commented 11 months ago

Aren't you applying some dep exclusions? Looking at Maven dep tree of io.smallrye:smallrye-context-propagation, I can see that it transitively brings in Jakarta annotations via CDI dependency:

[INFO] io.smallrye:smallrye-context-propagation:jar:2.1.0
[INFO] +- org.eclipse.microprofile.context-propagation:microprofile-context-propagation-api:jar:1.3:compile
[INFO] +- org.eclipse.microprofile.config:microprofile-config-api:jar:3.0.2:compile
[INFO] +- io.smallrye:smallrye-context-propagation-api:jar:2.1.0:compile
[INFO] +- io.smallrye:smallrye-context-propagation-storage:jar:2.1.0:compile
[INFO] +- jakarta.enterprise:jakarta.enterprise.cdi-api:jar:4.0.1:provided
[INFO] |  +- jakarta.enterprise:jakarta.enterprise.lang-model:jar:4.0.1:provided
[INFO] |  +- jakarta.annotation:jakarta.annotation-api:jar:2.1.1:provided
[INFO] |  +- jakarta.el:jakarta.el-api:jar:5.0.0:provided
[INFO] |  +- jakarta.interceptor:jakarta.interceptor-api:jar:2.1.0:provided
[INFO] |  \- jakarta.inject:jakarta.inject-api:jar:2.0.1:provided
[INFO] \- org.jboss.threads:jboss-threads:jar:3.4.2.Final:compile
[INFO]    +- org.jboss.logging:jboss-logging:jar:3.5.0.Final:compile
[INFO]    \- org.wildfly.common:wildfly-common:jar:1.5.0.Final:compile
manovotn commented 11 months ago

Ah, now I see, the CDI API dep is now marked as provided which is why you aren't getting it. This was changed by @radcortez in this commit. I am not sure if that was intentional or a mistake?

FTR this used to be compile dep and I don't see why it couldn't stay that way but maybe there was an issue with proliferating specific CDI version this way :shrug:

radcortez commented 11 months ago

We usually mark the dependencies coming from Jakarta as provided because most of our components will be used in a runtime that already provides these dependencies.

On the other hand, we have components that can be used independently. In this case, SmallRye Config is not shipping the jakarta annotations dependency which adds @Priority. I could add it there, or each project can also do it manually.

manovotn commented 11 months ago

On the other hand, we have components that can be used independently. In this case, SmallRye Config is not shipping the jakarta annotations dependency which adds @Priority. I could add it there, or each project can also do it manually.

I wouldn't explicitly add jakarta annotations dep - anyone missing those is likely to miss others that formerly transitively shipped with CDI dep. I'd rather vote for Mutiny adding the dependency if that's not too much of a problem :)

jponge commented 11 months ago

I can add that to mutiny-smallrye-context-propagation, let me have a look

jponge commented 11 months ago

Where do I find jakarta.enterprise.util.AnnotationLiteral?

Adding jakarta.annotation:jakarta.annotation-api isn't enough

Ladicek commented 11 months ago

You need the CDI API: jakarta.enterprise:jakarta.enterprise.cdi-api:4.0.1.

jponge commented 11 months ago

Thanks @Ladicek, I've added it as a provided dependency and it'll fix mutiny-smallrye-context-propagation