OsgiPlugin - Plugin never resolved service error
Asked Answered
H

3

9

I started developing a jira addon, but I'm getting errors.

My latest one, which I'm unable to fix is

[INFO] [talledLocalContainer] QuickReload - Plugin Installer ERROR [c.a.p.osgi.factory.OsgiPlugin] Plugin 'xy' never resolved service '&classname' with filter '(&(objectClass=xy.classname)(objectClass=xy.classname))'

What is going wrong here?

Hulse answered 10/8, 2016 at 13:1 Comment(0)
F
14

That happens when you try to inject on an object of your plugin another object of your plugin and you do it as if the another object was of another different plugin and was exported as a public OSGi service.

In JIRA, you can declare your plugin Java classes as components. That means that the instantiation and dependency injection (through constructor for example) will be automatically delegated on the Spring Framework which is part of JIRA. Usually we do this to lose care about instantiation and class dependencies. There are two types of components, public and private. Public components will be available to import for different plugins than yours. Other plugins can import them and then use them through dependency injection. Private components will work the same as public ones but other plugins will not be able to import or see them.

If you have one component, say A, which depends on another component, B, both of them part of your plugin, you should not import component B to be available for A because it is already part of your plugin. Before JIRA 7 for importing a component you placed on the atlassian-plugin.xml a <component-import> element. JIRA 7 onwards you put @ComponentImport before the constructor parameter when you do dependency injection through constructor.

So I think what you did wrong was to put <component-import> on a component that comes directly from your plugin instead of having <component>. Or if you have JIRA 7 or later version what you did wrong was to put @ComponentImport before a component of your own plugin and the solution there would be to remove that annotation. At least this last one was my case and removing that annotations from dependency injection of components coming from the same plugin I made it to work.

Fruge answered 14/9, 2016 at 14:29 Comment(1)
Based on the fact the OP used "xyz.classname" it is unclear, but as of spring-scanner 2.x you do not use @ComponentImport for anything within the same bundle, only services external to your context. For your own components you omit the annotation. So jpllossa's answer below is likely correct.Astrobiology
G
9

Had a similar problem like this when I was developing a plugin for Confluence v6.1.3. I was migrating from Atlassian Spring Scanner v1 to v2. After following the instructions in the Atlassian Spring Scanner v2 guide, I thought it was good to go but had this error:

[INFO] [talledLocalContainer] 2017-08-24 22:54:52,602 ERROR [localhost-startStop-1] [plugin.osgi.factory.OsgiPlugin] logAndClearOustandingDependencies Plugin 'com.confluenceservice.confluence.plugin.page-viewed' never resolved service '&pageViewedService' with filter '(&(objectClass=com.confluenceservice.confluence.plugin.PageViewedService)(objectClass=com.confluenceservice.confluence.plugin.PageViewedService))'

The cause of this error was the @ComponentImport PageViewedService service:

@Autowired
public AlertUserMacro(@ComponentImport PageViewedService service, 
        @ComponentImport PageManager pageManager) {
    //constructor...
}

This was ok in Spring Scanner v1 but not in Spring Scanner v2. The import isn't needed because PageViewedService is part of my plugin. I needed to import PageManager because its scope is outside of my plugin. The solution:

@Autowired
public AlertUserMacro(PageViewedService service, @ComponentImport PageManager pageManager) {
    //constructor
}

Hope this helps.

Garek answered 25/8, 2017 at 10:58 Comment(1)
Thanks for spring scanner v2, I basically went the wrong direction on this one because of Atlassian API docs.Savadove
I
0

I have just experienced this same error. Based on previous answers, I found the another root cause.

I have 2 plugins : PluginA and PluginB.

The pluginA provides a class plugina.ClassA correctly declared in its atlassian-plugin.xml with as public component.

The pluginB requires this Component plugina.ClassA of pluginA and has a valid reference with in its atlassian-plugin.xml.

The related error "[c.a.p.osgi.factory.OsgiPlugin] Plugin 'pluginB' never resolved service '&ClassA' with filter '(&(objectClass=plugina.ClassA)(objectClass=plugina.ClassA))'" is also occurring.

The root cause was not in the atlassian-plugin.xml declaration, but in the POM file.

In Plugin B, I have declared the dependency on Plugin A as follow

<dependency>
    <groupId>com.company</groupId>
    <artifactId>jira-plugin-a</artifactId>
    <version>${company.plugina.version}</version>
</dependency>

Without specifying the scope provided , the code of pluginA was embedded in pluginB.

The scope is required ...

<dependency>
    <groupId>com.company</groupId>
    <artifactId>jira-plugin-a</artifactId>
    <version>${company.plugina.version}</version>
    <scope>provided</scope>
</dependency>

Take care too with your dependencies.

Induline answered 7/6 at 10:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.