0

I want to create a sbt plugin

this is my project

build.sbt file:

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

main file with task

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")
    }
  )

}

During compiling I get an error: java.lang.NoClassDefFoundError: scala/collection/immutable/StringOps When I change the version to 2.12.6 - compiling is success. How I can fix error in 2.13?

Dmytro Mitin
  • 48,194
  • 3
  • 28
  • 66
Slavik Muz
  • 1,157
  • 1
  • 15
  • 28

1 Answers1

2

sbt is written in Scala 2.12

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

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

So you should use Scala 2.12 for sbt plugins.

Dmytro Mitin
  • 48,194
  • 3
  • 28
  • 66
  • ok, thanks, but how can I import plugin with scala 2.12 in a project with scala 2.13 ? – Slavik Muz Oct 17 '19 at 16:35
  • 1
    What do you mean by "import"? There is Scala version for plugin project (2.12) and there is Scala version for project where you use plugin (e.g. 2.13). – Dmytro Mitin Oct 17 '19 at 16:39
  • I mean that I have two projects: one is the scala plugin with version 2.12 which I pushed to artifactory so it has somehost/artifactory/sbt-release/com/test/test-plugin_2.12_1.0/0.1.0/test-plugin-0.1.0.jar. And I have the second project with scala 2.13 and I want to add plugin to this project, but it search plugin in forlder 2.13 – Slavik Muz Oct 17 '19 at 16:49
  • 1
    Do `sbt publishLocal` for the plugin project and write `addSbtPlugin("com.organization" % "sbt-yourplugin" % "pluginversion")` in `project/plugins.sbt` for the second project. – Dmytro Mitin Oct 17 '19 at 17:01