You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Václav Haisman <vh...@gmail.com> on 2021/09/12 08:50:27 UTC

Using Maven Resolver with DI in Spring Boot 2.5.x?

Hi.

I have been updating components in our application and noticed I could
update Maven Resolver as well. So I did and my build broke. It broke
because `org.eclipse.aether.impl.DefaultServiceLocator` is now
`@Deprecated` and we have it set up to fail the build when we use
deprecated APIs.

I started looking around and found this comment above
`DefaultServiceLocator`: "Use some out-of-the-box DI implementation
instead." OK, I thought, let's try it.

[...2 days later...]

I tried several approaches to get my app to instantiate and initialize
Maven Resolver components.

My successful attempt was to use `spring-guice` and to just use
`@EnableGuiceModules` and create a method on `@Configuration` class that
would return `@Bean` of `org.eclipse.aether.impl.guice.AetherModule`.
But this does not get me the entire system, it seems. So I had to look
around more and then I found
`org.apache.maven.repository.internal.MavenResolverModule`, which seem
more complete. However, even after using `MavenResolverModule`, I had to
add 33 more `bind()` statements into my own Guice `AbstractModule` bean
instance to get it to instantiate all the things it wants to use.

Is this how it is supposed to be done?

I had few dead ends before that successful attempt:

I tried using Spring's `Jsr330ScopeMetadataResolver`. It does find the
annotated classes but it ends up trying to register some of the beans
twice because they have the same name under default bean naming scheme
E.g.,
`org.eclipse.aether.internal.impl.synccontext.legacy.DefaultSyncContextFactory`
and
`org.eclipse.aether.internal.impl.synccontext.DefaultSyncContextFactory`
are both found and end up having the same bean name because the class
name is the same. Has anyone tried this route successfully, possibly
using some sort of different bean naming sheme?

Another approach I tried was to use Eclipse Sisu's `WireModule` instead
of the `MavenResolverModule` and my custom module. ... I actually do not
remember the details why it failed. I think it was something about
duplicate beans, too.

Do you guys have any success stories of how you did this entirely
without Guice / Sisu with just Spring Boot? What is the state of the art
approach to this in 2021?

-- 
VH


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Using Maven Resolver with DI in Spring Boot 2.5.x?

Posted by Václav Haisman <vh...@gmail.com>.
On 12. 09. 21 10:50, Václav Haisman wrote:
[...]

I forgot to link my test code:
https://github.com/wilx/spring-guice-maven-resolver-test

-- 
VH


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org