opentelemetry-java-contrib
opentelemetry-java-contrib copied to clipboard
maven-extension - plexus-component-annotations upgrade has deprecations
Component(s)
maven-extension
What happened?
See #1141 for the latest version update to plexus-component-annotations 2.2.0.
It appears that they have deprecated @Component in favor of just using the JSR330 annotations instead. Specifically, instead of using @Component it looks like we can just used @Named. For @Requirement it looks like the recommendation is to use constructor injection an annotate the ctor with @Inject.
Thanks I'll look at this.
Any traction? I think the extension is stalled without a refresh. π€π»
Thanks for the heads up. I'm on it, the migration doesn't work for me for the moment. I have to simplify the migration steps using a Maven build rather than Gradle and a few other things to be able to engage with Maven community.
Some findings so far:
- Documentation
- https://maven.apache.org/maven-jsr330.html
- https://github.com/eclipse/sisu.plexus/wiki/Plexus-to-JSR330
- The maven-sisu-plugin with
@Namedand@Injectjust generatesMETA-INF/sisu/javax.inject.Named - When in the past, the
plexus-component-metadata:generate-metadatadid generateMETA-INF/plexus/components.xml - TODO clarify if we should update
META-INF/maven/extension.xmlMETA-INF/services/io.opentelemetry.maven.handler.MojoGoalExecutionHandler
- Differences in behavior when adopting JSR 330 with Maven 3.9.6: See table below.
See test Maven extensions https://github.com/cyrille-leclerc/maven-extension-test
| Maven Extension API | Maven Event | Extension loading mechanism | |||
|---|---|---|---|---|---|
| ${maven.home}/lib/ext | mvn -Dmaven.ext.class.path= | pom.xml's <extensions> | .mvn/extensions.xml | ||
| JSR330 | AbstractExecutionListener | π΄ | π΄ | π΄ | π΄ |
| JSR330 | AbstractMavenLifecycleParticipant#afterSessionStart | π’ | π’ | π΄ | π’ |
| JSR330 | AbstractMavenLifecycleParticipant#afterProjectsRead | π’ | π’ | π’ | π’ |
| JSR330 | AbstractMavenLifecycleParticipant#afterSessionEnd | π’ | π’ | π’ | π’ |
| JSR330 | AbstractEventSpy#init | π’ | π’ | π΄ | π’ |
| JSR330 | AbstractEventSpy#onEvent | π’ | π’ | π΄ | π’ |
| JSR330 | AbstractEventSpy#close | π’ | π’ | π΄ | π’ |
The OpenTelemetry Maven Extension primarily relies on AbstractExecutionListener which is not supported by Maven's JSR-330 / Sisu APIs but supported by Maven's Plexus APIs.
In order o migrate from Plexus to JSR-330/Sisu APIs, we have either to see with the MAven community if AbstractExecutionListener can b supported by the JSR-330/Sisu APIs or change the APIs we use.
@hboutemy, hello! A few years ago, I discussed with you the challenges we faced with the OpenTelemetry Maven Extension to replace the Plexus APIs by JSR-330/Sisu. As we are trying once more to adopt JSR-330/Sisu, I spent the time to detail our problems in the table above with the Maven Extension Events that are missing when using JSR-330/Sisu. Could you please provide us some guidance on how to move forward?
FYI
- https://github.com/open-telemetry/opentelemetry-java-contrib/pull/1320
Hi @cyrille-leclerc , thanks for the heads up
I'm surprised AbstractExecutionListener injection works with Plexus but not Sisu: I did my own study a few years ago https://maven.apache.org/studies/extension-demo/ (from source code https://github.com/apache/maven-studies/tree/maven-extension-demo ) and I did not detect that discrepency
reproducing the issue you're facing with such a little project is our best bet to dive into the issue you're facing
I'm surprised AbstractExecutionListener injection works with Plexus but not Sisu
ok, re-reading your example and mine, we only tested AbstractExecutionListener with Sisu/JSR 330, not Plexus and its annotations: do you have an example of Plexus annotations working for AbstractExecutionListener?
Thanks HervΓ©, I'll double check with Plexus container.
ok, I had a new look at it and now I understand and can explain: AbstractExecutionListener is not used by Maven core as components (be it Plexus, Sisu or JSR-330), only MavenLifecycleParticipant and EventSpy are components
I updated my extension demo to try to be more clear on it: https://maven.apache.org/studies/extension-demo/
feedback appreciated if more clarification is needed
You are right @hboutemy ,
I have added Plexus @Component tests and results to my example https://github.com/cyrille-leclerc/maven-extension-test/blob/main/README.md
AbstractMavenLifecycleParticipant#afterProjectsRead() and AbstractMavenLifecycleParticipant#afterSessionEnd() are the 2 only events that are triggered consistently across the 4 mechanism to load a Maven extension: ${maven.home}/lib/ext, mvn -Dmaven.ext.class.path=..., pom.xml's <extensions>, and .mvn/extensions.xml.
I think I got confused with AbstractExecutionListener due to the page Example: Using Maven 3 lifecycle extension - Lifecycle Extension Points and the statement:
You can extend multiple classes depending on your needs:
org.apache.maven.execution.AbstractExecutionListener,org.apache.maven.AbstractMavenLifecycleParticipant,org.apache.maven.eventspy.AbstractEventSpy
The statement above let me think that Maven extensions could extend any of AbstractExecutionListener, AbstractMavenLifecycleParticipant, and AbstractEventSpy through a Plexus extension to hook into Maven lifecycle events but it's not the case, only Plexus instances of AbstractMavenLifecycleParticipant and EventSpy are automatically hooked in the lifecycle.
Your page Maven Core Extension Demo Study is clearer than Example: Using Maven 3 lifecycle extension - Lifecycle Extension Points