1

我尝试使用 sbt-osgi 插件,但无法加载它AutoPlugin,编译器拒绝编译我的代码。

首先,我将最新版本的插件添加到project/plugins.sbt

resolvers += Classpaths.sbtPluginSnapshots
addSbtPlugin("com.typesafe.sbt" % "sbt-osgi" % "0.8.0-SNAPSHOT")

之后,我将 sbt 版本设置为project/build.properties

sbt.version=0.13.7

然后,我创建project/Build.scala了以下内容:

import sbt._
import com.typesafe.sbt.osgi.SbtOsgi

object Build extends sbt.Build {
  lazy val fooProject = Project("foo-project", file("."))
    .enablePlugins(SbtOsgi)
}

但这会导致以下错误消息:

[info] Loading project definition from .../sbt-osgi-test/project
[info] Compiling 1 Scala source to .../sbt-osgi-test/project/target/scala-2.10/sbt-0.13/classes...
[error] .../sbt-osgi-test/project/Build.scala:10: type mismatch;
[error]  found   : com.typesafe.sbt.osgi.SbtOsgi.type
[error]  required: sbt.Plugins
[error]     .enablePlugins(SbtOsgi)
[error]                    ^
[error] one error found
[error] (compile:compile) Compilation failed

此错误消息没有任何意义,因为AutoPluginextends sbt.Plugins。可能是什么问题呢?

4

2 回答 2

1

问题的原因是 sbt-osgi 插件的 0.8.0-SNAPSHOT 版本坏了:

% javap -cp ~/.ivy2/cache/scala_2.10/sbt_0.13/com.typesafe.sbt/sbt-osgi/jars/sbt-osgi-0.8.0-SNAPSHOT.jar com.typesafe.sbt.osgi.SbtOsgi$
Compiled from "SbtOsgi.scala"
public final class com.typesafe.sbt.osgi.SbtOsgi$ implements sbt.Plugin {
  public static final com.typesafe.sbt.osgi.SbtOsgi$ MODULE$;
  public static {};
  public scala.collection.Seq<sbt.Init<sbt.Scope>.Setting<?>> settings();
  public scala.collection.Seq<sbt.Init<sbt.Scope>.Setting<?>> projectSettings();
  public scala.collection.Seq<sbt.Init<sbt.Scope>.Setting<?>> buildSettings();
  public scala.collection.Seq<sbt.Init<sbt.Scope>.Setting<?>> globalSettings();
  public com.typesafe.sbt.osgi.OsgiKeys$ OsgiKeys();
  public scala.collection.Seq<sbt.Init<sbt.Scope>.Setting<?>> osgiSettings();
  public scala.collection.Seq<sbt.Init<sbt.Scope>.Setting<?>> defaultOsgiSettings();
}

可以看到,它扩展sbt.Plugin了,但不是预期的sbt.Plugins。解决方案是等待上游修复。

于 2015-02-07T01:27:09.587 回答
0

我对sbt/sbt#1844的回复

如果我相信https://repo.scala-sbt.org/scalasbt/sbt-plugin-snapshots/com.typesafe.sbt/sbt-osgi/scala_2.10/sbt_0.13/0.8.0-SNAPSHOT/上的时间戳jars/快照自 2014 年 1 月 5 日 22:07 起未更新,与 sbt/sbt-osgi@c6dd29a 上的日期一致。当时还没有发布自动插件。

于 2015-02-07T07:12:20.053 回答