3

我正在尝试为 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 ,将 @ExportAsService 添加到该类都无济于事。似乎弹簧扫描仪没有将我的类检测为组件。有没有人能够克服这个问题?我已经写信给 atlassian 社区,但到目前为止还没有任何消息。

4

1 回答 1

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 弹簧扫描仪之间存在差异,请确保使用正确的版本。请参阅参考资料

于 2017-02-21T13:59:58.713 回答