我正在尝试编写一个框架以使编写 Scala 编译器插件更容易,我正在做的是在 Scala quasiquotes 之上编写一个框架。所以我的项目依赖于宏天堂的宏以及 scala-compiler 和 scala-reflect 库。
我按照此处提到的说明编写了一个 SBT 构建脚本:https ://github.com/scalamacros/sbt-example-paradise/blob/master/project/Build.scala
并使用 scalaVersion 2.11.0-SNAPSHOT, 2.10.3-SNAPSHOT, 2.10.3-RC1, 2.10.2 编译我的项目,但它们都不起作用。这是我的 sbt 构建脚本:
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)
}
使用 scalaVersion 2.10-3-RC1,我收到以下错误:
[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)
使用 scalaVersion 2.11.0-SNAPSHOT,我收到以下错误:
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)
在使用 2.10.3-SNAPSHOT 版本时,我得到了以下信息:
[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
而且 2.10.2 版根本无法解决 scala-library、scala-reflect 和 2.10.2 的依赖关系(如 2.10.3-RC1)!
我的问题是,是否有可能混合编译器 API 和宏 API 并使它们在 SBT 下工作,如果是的话,我的构建脚本到底有什么问题?