Question

I am trying to write a framework to make writing Scala compiler plugins easier, what I am doing is writing a framework on top of the Scala quasiquotes. So my project depends on macros from macro-paradise and both scala-compiler and scala-reflect libraries.

I wrote an SBT build script by following the instructions mentioned here: https://github.com/scalamacros/sbt-example-paradise/blob/master/project/Build.scala

And used scalaVersion 2.11.0-SNAPSHOT, 2.10.3-SNAPSHOT, 2.10.3-RC1, 2.10.2 to compile my project, but neither of them worked. Here is my sbt build script:

import sbt._
import Keys._

object LombrelloBuildSettings {
  val sversion = "2.10.3-SNAPSHOT"
  val buildSettings = Defaults.defaultSettings ++ Seq(
  name := "lombrello",
  organization := "ch.usi.inf.l3",
  version := "0.1-SNAPSHOT",
  scalacOptions ++= Seq("-unchecked", "-deprecation", "-feature"),
  scalaVersion := sversion,
  scalaOrganization := "org.scala-lang.macro-paradise",
  resolvers += Resolver.sonatypeRepo("snapshots"),
  licenses := ("BSD 3-Clause", new java.net.URL("http://opensource.org/licenses/BSD-3-Clause")) :: Nil,
  libraryDependencies ++= Seq("org.scala-lang.macro-paradise" % "scala-reflect" % sversion,
      "org.scala-lang" % "scala-compiler" % sversion),
  addCompilerPlugin("org.scala-lang.plugins" % "macro-paradise" % "2.0.0-SNAPSHOT" cross CrossVersion.full))
}

object LombrelloBuild extends Build {
  import LombrelloBuildSettings._

  lazy val root: Project = Project(
    "root",
    file("."),
    settings = buildSettings ++ Seq(
      run <<= run in Compile in tests
    )
  ) aggregate (main, tests)

  lazy val main: Project = Project(
    "main",
    file("src/main"),
    settings = buildSettings

  )

 lazy val tests: Project = Project(
   "tests",
   file("src/test"),
   settings = buildSettings ++ Seq(name := "tests")) dependsOn (main)
}

Using the scalaVersion 2.10-3-RC1, I get the following error:

[warn]  :::::::::::::::::::::::::::::::::::::::::::::: 
[warn]  ::          UNRESOLVED DEPENDENCIES         :: 
[warn]  :::::::::::::::::::::::::::::::::::::::::::::: 
[warn]  :: org.scala-lang.macro-paradise#scala-library;2.10.3-RC1: not found 
[warn]  :: org.scala-lang.macro-paradise#scala-reflect;2.10.3-RC1: not found 
[warn]  :: org.scala-lang.macro-paradise#scala-compiler;2.10.3-RC1: not found 
[warn]  :::::::::::::::::::::::::::::::::::::::::::::: 
sbt.ResolveException: unresolved dependency: org.scala-lang.macro-paradise#scala-library;2.10.3-RC1: not found 
unresolved dependency: org.scala-lang.macro-paradise#scala-reflect;2.10.3-RC1: not found 
unresolved dependency: org.scala-lang.macro-paradise#scala-compiler;2.10.3-RC1: not found 
    at sbt.IvyActions$.sbt$IvyActions$$resolve(IvyActions.scala:213) 
    at sbt.IvyActions$$anonfun$update$1.apply(IvyActions.scala:122) 

Using, scalaVersion 2.11.0-SNAPSHOT, I got the following error:

 java.lang.NoClassDefFoundError: scala/tools/nsc/typechecker/TypersTracking$class
    at org.scalalang.macroparadise.Plugin$$anon$1.<init>(Plugin.scala:20)
    at org.scalalang.macroparadise.Plugin.<init>(Plugin.scala:20)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

While using the version 2.10.3-SNAPSHOT I got the following:

 [warn]     ::::::::::::::::::::::::::::::::::::::::::::::
 [warn]     ::          UNRESOLVED DEPENDENCIES         ::
 [warn]     ::::::::::::::::::::::::::::::::::::::::::::::
 [warn]     :: org.scala-lang.plugins#macro-paradise_2.10.3-SNAPSHOT;2.0.0-SNAPSHOT: not found
 [warn]     ::::::::::::::::::::::::::::::::::::::::::::::
 sbt.ResolveException: unresolved dependency: org.scala-lang.plugins#macro-paradise_2.10.3-SNAPSHOT;2.0.0-SNAPSHOT: not found

And version 2.10.2 couldn't resolve the dependencies of scala-library, scala-reflect and 2.10.2 at all (like 2.10.3-RC1)!

My question is, is it at all possible to mix both compiler API and Macro API and make them work under SBT, if yes what exactly is wrong with my build script?

Was it helpful?

Solution

It appeared that I used some wrong settings in my SBT configuration. I didn't need to change the scalaOrganization, neither needed to add macro-paradise to my library dependencies. so the settings should become like:

val sversion = "2.10.2"
val buildSettings = Defaults.defaultSettings ++ Seq(
    name := "lombrello",
    organization := "ch.usi.inf.l3",
    version := "0.1-SNAPSHOT",
    scalacOptions ++= Seq("-unchecked", "-deprecation", "-feature"),
    scalaVersion := sversion,
    resolvers += Resolver.sonatypeRepo("snapshots"),
    licenses := ("BSD 3-Clause", new java.net.URL("http://opensource.org/licenses/BSD-3-Clause")) :: Nil,
    libraryDependencies ++= Seq("org.scala-lang" % "scala-reflect" % sversion,
        "org.scala-lang" % "scala-compiler" % sversion),
    addCompilerPlugin("org.scala-lang.plugins" % "macro-paradise" % "2.0.0-SNAPSHOT" cross CrossVersion.full)
    )

All credits go to Eugene Burmako in this comment.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top