我正在尝试为jira编写一个事件监听器插件。当我采用旧的方式(最新的Atlassian SDK 6.2.9)并将这两行放在
时<component key="eventListener" class="jira.plugins.listeners.MyEventListener"/>
<component-import key="eventPublisher" class="com.atlassian.event.api.EventPublisher"/>
并尝试打包插件我收到警告说I cannot use component/component-import statement inside plugin descriptor file when Atlassian plugin key is set
。最新的SDK使用Spring Scanner,它在骨架创建过程中自动添加到pom.xml文件中,并强烈建议使用。所以我从atlassian-plugin.xml文件中删除了这两行,并尝试用相应的注释替换它们:
@Component
public class MyEventListener{
@Inject
public MyEventListener(@ComponentImport EventPublisher eventPublisher){
eventPublisher.register(this);
}
}
我可以通过这种方式编译和打包,但是当我在正在运行的Jira实例上安装它时,在插件的描述中它显示This plugin has no modules
。我已经尝试将@Component更改为@Named,将addind @ExportAsService更改为该类都无济于事。似乎spring扫描器没有检测到我的类作为组件。有没有人能够克服这个问题?我写信给atlassian社区,但到目前为止还没有得到任何消息。
答案 0 :(得分:1)
将Spring Scanner maven插件配置为以详细模式执行,并确保在构建期间使用包含模式处理您的类。
<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>
如果一切正常,在构建之后,您的组件将列在文件 target / classes / META-INF / plugin-components / component
中如果在库模块中定义@Component(作为托管插件的依赖项),您还可以使用配置元素生成组件元数据
<scannedDependencies>
<dependency>
<groupId>your.library.group.id</groupId>
<artifactId>your-library</artifactId>
</dependency>
</scannedDependencies>
注意:V1和V2弹簧扫描仪之间存在差异,请确保使用正确的版本。请参阅reference。