Search code examples
intellij-ideaintellij-plugin

ServiceManager#getService returns null


I have an application service declared in plugin.xml as

<extensions defaultExtensionNs="com.intellij">
    <applicationService serviceImplementation="MyService"/>
</extensions>

but the following test fails

public class MyServiceTest extends LightCodeInsightFixtureTestCase {
  public void test() throws Exception {
    MyService service = ServiceManager.getService(MyService.class);
    assertNotNull(service);
  }
}

I've tried placing breakpoint with a condition in DefaultPicoContainer#registerComponent(ComponentAdapter) but it never triggers. And there are no errors in the log.


Solution

  • The plugin was ignored because there was another plugin in ~\.IdeaIC12\system\plugins-sandbox\plugins with the same <name> in plugin.xml.

    Inspect IdeaPluginDescriptorImpl[] at PluginManager#initializePlugins to check if your plugin is being loaded.