2

I'm trying to write an event listener plugin for jira. When I go the old way (which the latest Atlassian SDK 6.2.9 does) and put these 2 lines

<component key="eventListener" class="jira.plugins.listeners.MyEventListener"/>
<component-import key="eventPublisher" class="com.atlassian.event.api.EventPublisher"/>

and try to package the plugin I get a warning saying that I cannot use component/component-import statement inside plugin descriptor file when Atlassian plugin key is set. The latest SDK uses Spring Scanner, which is added to the pom.xml file automatically during the skeleton creation and which documentation strongly recommends. So I remove those two lines from the atlassian-plugin.xml file and try to substitute them with corresponding annotations:

@Component
public class MyEventListener{
   @Inject
   public MyEventListener(@ComponentImport EventPublisher eventPublisher){
        eventPublisher.register(this);
   }

}

I can compile and package it this way, but when I install it on a running Jira instance, in the description of the plugin it says This plugin has no modules. I've tried changing @Component to @Named , addind @ExportAsService to the class all to no avail. It seems spring scanner does not detect my class as a component. Has anyone been able to overcome this issue? I've written to atlassian community but haven't gotten any news so far.

Mikayil Abdullayev
  • 12,117
  • 26
  • 122
  • 206
  • I've recently come up against this too, I still haven't figured out how to get the module to show up in the list, but I've noticed that my `@EventListener`s are actually being called anyway. Have you tried adding some logging in your `@EventListener` methods and/or the constructor? – Joshua Webb Feb 04 '17 at 07:41
  • Yes, I've added logging and I don't get anything logged. – Mikayil Abdullayev Feb 05 '17 at 15:30
  • If you have the Atlassian plugin key set then you can't use the component tags in the atlassian plugin xml. This means you are using Spring Scanner. The old way was to put the component tag in the atlassian plugin xml and not have a plugin key set. – jpllosa Nov 12 '18 at 14:43

1 Answers1

1

Configure the Spring Scanner maven plugin to execute in verbose mode, and make sure that your class is processed during the build using the inclusion patterns.

    <plugin>
        <groupId>com.atlassian.plugin</groupId>
        <artifactId>atlassian-spring-scanner-maven-plugin</artifactId>
        <executions>
            <execution>
                <goals>
                    <goal>atlassian-spring-scanner</goal>
                </goals>
                <phase>process-classes</phase>
            </execution>
        </executions>
        <configuration>
            <includeExclude>+your.package.goes.here.*</includeExclude>
            <verbose>true</verbose>
        </configuration>
    </plugin>

If everything fine, after the build your component will be listed in the file target/classes/META-INF/plugin-components/component

In case the @Component is defined in a library module (as a dependency of the hosting plugin), you can also generate the component metadata using the configuration element

            <scannedDependencies>
                <dependency>
                    <groupId>your.library.group.id</groupId>
                    <artifactId>your-library</artifactId>
                </dependency>
            </scannedDependencies>

Note: there is a difference between the V1 and V2 spring scanner, make sure you use the right version. See reference.

pharsfalvi
  • 787
  • 1
  • 8
  • 12
  • It should be made clear (it wasn't clear to me) that `` specifies paths that should **not** be scanned. [The docs](https://bitbucket.org/atlassian/atlassian-spring-scanner) explain its purpose as: "The paths to ignore - typically you don't need this tag at all". However, it still remains unclear to me a) how to specify more than one path and b) what a minus sign could mean in opposite to the plus sign in the example. – not2savvy Mar 22 '19 at 18:49