Repository navigation
Description
Problem
Currently, Listener (and its subtypes ExecutionListener, RepositoryListener) must be registered programmatically via Session.registerListener(). This requires the caller to already have a live Session instance, which means core extensions loaded at startup via META-INF/services/ have no way to register themselves as listeners — they have no Session yet when they are instantiated.
Proposal
Auto-discover Listener implementations that also implement SpiService: during session initialization, Maven would iterate the already-discovered SpiService instances, filter those that are instanceof Listener, and call session.registerListener() on each automatically.
This requires no interface inheritance between Listener and SpiService (which would create a circular module dependency since maven-api-spi depends on maven-api-core). The two interfaces remain independent; the convention is purely in Maven's bootstrap wiring.
What this enables
A core extension in maven-api-spi could implement both SpiService and ExecutionListener (or RepositoryListener) and receive typed event callbacks without any explicit registration, simply by being declared in META-INF/services/.
What this does not change
Listenerstays inmaven-api-core,SpiServicestays inmaven-api-spi— no module restructuring needed.- Programmatic
session.registerListener()continues to work as before. - No new interface hierarchy is introduced.
Additional work: document exception-handling contract on Listener
The current Listener/ExecutionListener/RepositoryListener Javadoc says nothing about what happens when onEvent() throws. In practice, both dispatchers (EventSpyImpl for execution events, MavenRepositoryListener for repository events) catch RuntimeException and log a WARN, swallowing the exception so that one misbehaving listener cannot affect others or the build. This contract should be made explicit in the Listener interface Javadoc so extension authors know they cannot signal build failures through a thrown exception — for that, afterProjectsRead() on a lifecycle participant SPI (see #13647) is the appropriate mechanism.
Context
This came up during review of #13647 (Maven 4 lifecycle participation SPI). The LifecycleParticipant SPI introduced there extends SpiService directly and uses its own dispatcher, which duplicates what the Listener dispatch infrastructure already provides for execution-phase callbacks. Auto-discovering Listener+SpiService implementations would allow that SPI to compose cleanly with the existing event system.
Activity
[apache#13805] Auto-discover Listener implementations that implement …
fix: guard SPI listener discovery against LookupException and add Eve…