【问题标题】:Automatic META-INF/services generation in Scala and SBT for ServiceLoader在 Scala 和 SBT 中为 ServiceLoader 自动生成 META-INF/服务
【发布时间】:2015-10-22 13:17:24
【问题描述】:

在 Scala 和 SBT 中,有没有办法通过注释类自动生成 META-INF/services/* 资源文件供 java.util.ServiceLoader 使用,就像 Google Auto Service 对 Java 项目所做的那样?

package foo.bar

import my.exported.ServiceInterface

@AutoService[ServiceInterface]
class MyService extends ServiceInterface{
  // …
}

在资源文件夹中自动生成文件META-INF/services/my.exported.ServiceInterface。该文件将包含:

foo.bar.MyService 

(我认为我不能直接使用 Google Auto Service,因为它不适用于 Scala 类——请参阅this comment on a realm-java github issue。)

【问题讨论】:

    标签: scala sbt annotation-processing serviceloader


    【解决方案1】:

    请考虑使用https://github.com/nyavro/spi-plugin

    此插件中使用的方法与使用注释不同 - 它使用整个包作为接口的来源,并适用于接口实现的包。

    【讨论】:

      猜你喜欢
      • 2017-11-04
      • 1970-01-01
      • 2016-10-02
      • 1970-01-01
      • 1970-01-01
      • 2020-08-19
      • 2019-04-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多