0

My sample sbt plugin is compiling fine with scala version 2.10.6. I am trying to upgrade scalaVersion := "2.11.7" in the sbt plugin build.sbt.

It breaks with the followinng CTE :-

/Users/mogli/gitrepos/study/SbtPlugins/ScalaPlugin/src/main/scala/base/BasePlugin.scala:21: can't expand macros compiled by previous versions of Scala [error]
val projects = thisProject.value.dependencies

This was working fine with scalaVersion := "2.10.6" as suggested by Micro Dotta in below question :-

accessing dependent (not child) projects in sbt plugin

Simplified sbt plugin BasePlugin.scala:

package base

import sbt.{ThisBuild, Def, TaskKey, AutoPlugin}
import sbt._
import Keys._


object BasePlugin extends AutoPlugin {

  object autoImport {
    lazy val customtask: TaskKey[Unit] = TaskKey("customtask")
  }

  import autoImport.customtask


  override def projectSettings: Seq[Def.Setting[_]] = Seq(
    customtask := {
      val projects = thisProject.value.dependencies
      projects map println
    }
  )
}

How to get it work with scalaVersion := "2.11.7"? I want this plugin to use with projects that are using scal version 11.

James Z
  • 12,209
  • 10
  • 24
  • 44
mogli
  • 1,549
  • 4
  • 29
  • 57

2 Answers2

0

Try this:

  override def projectSettings: Seq[Def.Setting[_]] = Seq(
        customtask := {
          val projects = thisProject.value.dependencies
          projects map println
        },
        scalaVersion := "2.11.7"
      )
jiayp89
  • 523
  • 2
  • 10
0

SBT build defintions are tied to a scala version by the sbt version they use:

  • sbt 0.12.x build definitions and code must be compiled against scala 2.9.x
  • sbt 0.13.x build definitions and code must be compiled against scala 2.10.x

since 1.0.0 sbt is compiled against scala version 2.12 and requires Java 8

So,

there is no sbt version where sbt build defintions can be compiled with scala 2.11 (at least not without risking errors).

You can manipulate the sbt version you are using by setting it in project/build.properties:

sbt.version=1.0.0

Make sure you use a current sbt wrapper script.

Sascha Kolberg
  • 7,092
  • 1
  • 31
  • 37