0

我想创建一个 sbt 插件

这是我的项目

build.sbt 文件:

lazy val root = (project in file(".")).
  settings(
    name := "test-plagin",
    version := "0.1.0",
    organization := "com.test",
    scalaVersion := "2.13.0",
    sbtPlugin := true,
  )

带有任务的主文件

import sbt.{AutoPlugin, TaskKey}

object HelloPlugin extends AutoPlugin {

  object autoImport {
    val sayHello: TaskKey[Unit] = TaskKey("saying hello")
  }

  import autoImport._
  override def projectSettings = Seq(

    sayHello := {
      println("hello")
    }
  )

}

在编译期间出现错误: java.lang.NoClassDefFoundError: scala/collection/immutable/StringOps 当我将版本更改为 2.12.6 - 编译成功。如何修复 2.13 中的错误?

4

1 回答 1

2

sbt 是用 Scala 2.12 编写的

https://github.com/sbt/sbt/blob/develop/project/Dependencies.scala#L9

https://github.com/sbt/sbt/issues/5032

所以你应该为 sbt 插件使用 Scala 2.12。

于 2019-10-17T16:28:31.060 回答