eclipse-sisu / sisu.plexus

Sisu Plexus
https://www.eclipse.org/sisu
Eclipse Public License 1.0
4 stars 11 forks source link

Cannot create custom Guice bindings with a maven extention #41

Closed HomeOfTheWizard closed 1 year ago

HomeOfTheWizard commented 1 year ago

Hi, I tried to use a custom Guice module to bind an specific instance of class in an extension, following this tutorial. https://github.com/eclipse/sisu.plexus/wiki/Plexus-to-JSR330#custom-bindings

But couldnt make it work. https://github.com/HomeOfTheWizard/demo-maven-extension.

When I lookup in the container, I see the module is picked up, but cannot find the component that I bind with the module. Here is what I do

session.getContainer().lookup(AbstractModule.class,"myModule"); //gets MyModule.class
session.getContainer().hasComponent("myComponent"); // return false.

I saw that the session.getContainer() is deprecated. Maybe there is a better API to search in the sisu container ? Can you please help me 🙏

dsyer commented 1 year ago

I think it might work, actually. You can see that someone thought about it here: https://maven.apache.org/ref/3.9.0/maven-core/core-extensions.html (look for commented out com.google.inject packages). I updated my sample https://github.com/scratches/plugin-demo to use this approach.

HomeOfTheWizard commented 1 year ago

Ok I see now. it was my META-INF/maven/extension.xml file that wasnt exported correctly. indeed it works !