Search code examples
scalaplugins

Trying to test creating a Scala Plugin with version 2.13, getting java.lang.NoClassDefFoundError sclaa Serializable


running into this error when trying to follow an SBT Plugin tutorial

 java.lang.NoClassDefFoundError: scala/Serializable
[error] sbt.std.InputWrapper$.valueMacroImpl(InputWrapper.scala:136)
[error] java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[error] java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[error] java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[error] java.base/java.lang.reflect.Method.invoke(Method.java:566)
[error] scala.reflect.macros.runtime.JavaReflectionRuntimes$JavaReflectionResolvers.$anonfun$resolveJavaReflectionRuntime$6(JavaReflectionRuntimes.scala:51)

Worthy note: I'm trying to use a later version of scala, ver "2.13.11", the publisher is using "2.10.4".

What am I missing or what's 2.13 Scala missing that could cause this? What's the solution?


Solution

  • As @LuisMiguelMejíaSuárez said, the problem is the scala version that you are using.

    There is an issue already closed about Cannot compile SBT plugin under Scala 2.13.0. Where the maintainer of the repo says

    sbt plugin should be created like this:

    lazy val root = (project in file("."))
      .enablePlugins(SbtPlugin)  
      .settings(
        name := "sbt-something"
      )
    

    and Scala version should not be specified unless you're cross building between sbt 1.x and 0.13. There's no sbt available under 2.13.0, so expectation doesn't make sense.

    Also it's explained in the docs Sbt - Creating an auto plugin

    • sbt plugins must be compiled with Scala 2.12.x that sbt itself is compiled in. By NOT specifying scalaVersion, sbt will default to the Scala version suited for a plugin.

    One of the users that commented in the sbt issue mentioned above, created an sbt 1.x hello world where you can see used as the homepage of the example showed in Creating an auto plugin

    ThisBuild / version := "0.1.0-SNAPSHOT"
    ThisBuild / organization := "com.example"
    ThisBuild / homepage := Some(url("https://github.com/sbt/sbt-hello"))
    
    lazy val root = (project in file("."))
      .enablePlugins(SbtPlugin)
      .settings(
        name := "sbt-hello",
        pluginCrossBuild / sbtVersion := {
          scalaBinaryVersion.value match {
            case "2.12" => "1.2.8" // set minimum sbt version
          }
        }
      )