opentelemetry-java-contrib icon indicating copy to clipboard operation
opentelemetry-java-contrib copied to clipboard

maven-extension - plexus-component-annotations upgrade has deprecations

Open breedx-splk opened this issue 1 year ago β€’ 11 comments

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.

breedx-splk avatar Jan 04 '24 22:01 breedx-splk

Thanks I'll look at this.

cyrille-leclerc avatar Jan 05 '24 12:01 cyrille-leclerc

Any traction? I think the extension is stalled without a refresh. 🀞🏻

breedx-splk avatar May 16 '24 20:05 breedx-splk

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 @Named and @Inject just generates META-INF/sisu/javax.inject.Named
  • When in the past, the plexus-component-metadata:generate-metadata did generate META-INF/plexus/components.xml
  • TODO clarify if we should update
    • META-INF/maven/extension.xml
    • META-INF/services/io.opentelemetry.maven.handler.MojoGoalExecutionHandler
  • Differences in behavior when adopting JSR 330 with Maven 3.9.6: See table below.

cyrille-leclerc avatar May 20 '24 09:05 cyrille-leclerc

See test Maven extensions https://github.com/cyrille-leclerc/maven-extension-test

Maven Extension APIMaven EventExtension loading mechanism
${maven.home}/lib/extmvn -Dmaven.ext.class.path=pom.xml's <extensions>.mvn/extensions.xml
JSR330AbstractExecutionListener πŸ”΄ πŸ”΄ πŸ”΄ πŸ”΄
JSR330AbstractMavenLifecycleParticipant#afterSessionStart 🟒 🟒 πŸ”΄ 🟒
JSR330AbstractMavenLifecycleParticipant#afterProjectsRead 🟒 🟒 🟒 🟒
JSR330AbstractMavenLifecycleParticipant#afterSessionEnd 🟒 🟒 🟒 🟒
JSR330AbstractEventSpy#init 🟒 🟒 πŸ”΄ 🟒
JSR330AbstractEventSpy#onEvent 🟒 🟒 πŸ”΄ 🟒
JSR330AbstractEventSpy#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.

cyrille-leclerc avatar May 21 '24 08:05 cyrille-leclerc

@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?

cyrille-leclerc avatar May 21 '24 08:05 cyrille-leclerc

FYI

  • https://github.com/open-telemetry/opentelemetry-java-contrib/pull/1320

cyrille-leclerc avatar May 21 '24 16:05 cyrille-leclerc

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

hboutemy avatar May 24 '24 02:05 hboutemy

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?

hboutemy avatar May 25 '24 08:05 hboutemy

Thanks HervΓ©, I'll double check with Plexus container.

cyrille-leclerc avatar May 25 '24 13:05 cyrille-leclerc

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

hboutemy avatar May 27 '24 06:05 hboutemy

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

cyrille-leclerc avatar May 27 '24 21:05 cyrille-leclerc