Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot compile SBT plugin under Scala 2.13.0 #5032

Closed
mr-git opened this issue Sep 4, 2019 · 4 comments
Closed

Cannot compile SBT plugin under Scala 2.13.0 #5032

mr-git opened this issue Sep 4, 2019 · 4 comments

Comments

@mr-git
Copy link

mr-git commented Sep 4, 2019

steps

SBT version: 1.2.8, 1.3.0

build.sbt:

lazy val `plugin-with-bug` = project.in(file("."))
sbtPlugin := true
scalaVersion := "2.13.0"
crossScalaVersions := Seq("2.12.9", "2.13.0")

src/main/scala/Bug.scala:

import sbt._

object Bug extends AutoPlugin {
  val key = settingKey[String]("key")
  override def requires: Plugins = plugins.JvmPlugin
  override def trigger: PluginTrigger = allRequirements
  override def globalSettings: Seq[Setting[_]] = Seq()
}

Run command: +compile or ++2.13.0; compile

problem

IJ]sbt:plugin-with-bug> ++2.13.0; compile
[info] Setting Scala version to 2.13.0 on 1 projects.
[info] Reapplying settings...
[info] Set current project to plugin-with-bug (in build file:/.../git/sbt-issue/)
[info] Compiling 1 Scala source to /.../sbt-issue/target/scala-2.13/sbt-1.0/classes ...
[error] /.../git/sbt-issue/src/main/scala/Bug.scala:4:31: exception during macro expansion: 
[error] java.lang.ClassNotFoundException: scala.Serializable
[error] 	at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:436)
[error] 	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
[error] 	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
[error] 	at sbt.std.KeyMacro$.settingKeyImpl(KeyMacro.scala:20)
[error]   val key = settingKey[String]("key")
[error]                               ^
[error] one error found

expectation

There are no compilation errors.
Compilation for Scala 2.13.0 must succeed.

notes

@mr-git mr-git added the Bug label Sep 4, 2019
@eed3si9n
Copy link
Member

eed3si9n commented Sep 4, 2019

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.

See also https://www.scala-sbt.org/1.x/docs/Plugins.html

@eed3si9n eed3si9n added not-a-🐛 and removed Bug labels Sep 4, 2019
@mr-git
Copy link
Author

mr-git commented Sep 5, 2019

thank you!

conclusion:

  • SBT 0.x runs only on Scala 2.10.x
  • SBT 1.x runs only on Scala 2.12.x
  • SBT 2.x will run only on Scala 2.13.x or 3.0.x
  • SBT 3.x will run only on Scala 3.0.x or Scala 3.1.x

It would be lovely to see such table/mapping in SBT docs for plugin development

@mr-git mr-git closed this as completed Sep 5, 2019
@logc
Copy link

logc commented Nov 20, 2020

I ran into this exact issue by starting my plugin from sbt new scala/scala-seed.g8 and then following the SBT reference manual. Thanks for the solution, and the reference of SBT/Scala versions! Both should probably go into the manual

The plugin doc is confusing. It shows "bare" configurations in the complete example, and it starts by introducing Commands, then advises against using them ...

So, I created a minimal working example in this repository: https://github.com/logc/sbt-hello . Please comment there if you find that it does not follow current best practices. Otherwise, I hope it helps someone else!

@eed3si9n
Copy link
Member

@logc I've split this into a new issue - #6131

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants