如何在 Gradle 项目中创建 Karaf shell 命令

How to create Karaf shell command in Gradle project

我正在尝试创建自己的 Karaf shell 命令并且我愿意使用 Gradle 来执行此操作,因为整个项目都在 Gradle.

到目前为止我找到的唯一相关文档在这里 http://karaf.apache.org/manual/latest/#_shell_commands 它说

See [examples/karaf-command-example] to add your own shell commands.

Examples 是使用 MAVEN 创建的,绝对没有描述那里发生了什么魔法以及结果包中应该出现什么以便我可以在 Gradle.[=15= 中重现它]

有人可以告诉我如何在 Gradle 项目中实现同样的目标吗?
Karaf 如何识别 Bundle 中存在哪些命令?

随着时间的推移,我没有找到如何在 gradle 中制作 相同的 东西,但我遇到了给出相同结果的解决方案 - 使用 OSGI 声明式服务。

此处有更多详细信息(查找 osgi.command.scope):
http://blog.vogella.com/2016/09/26/configuring-osgi-declarative-services/

这里是示例代码,它允许 运行 命令 some:command 带有一个可选的字符串参数。

package some.application;

import org.osgi.service.component.annotations.Component;

@Component(
    service=SomeCommand.class,
    property = {"osgi.command.scope=some", "osgi.command.function=command"}
)
public class SomeCommand {

    public void command() {
        System.out.println("SomeCommand: " + "<no args>");
    }

    public void command(String param) {
        System.out.println("SomeCommand: " + param);
    }
}