解决 SBT 中 Scala 宏和编译器框架的依赖关系



我正在尝试编写一个框架以使编写Scala编译器插件更容易,我正在做的是在Scala准引号之上编写一个框架。所以我的项目依赖于来自宏天堂的宏以及 scala 编译器和 scala 反射库。

我按照此处提到的说明编写了一个 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) 

使用scala版本2.11.0-快照,我收到以下错误:

 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 下工作,如果是,我的构建脚本到底出了什么问题?

看来我在 SBT 配置中使用了一些错误的设置。我不需要更改 scalaOrganization,也不需要向我的库依赖项添加宏天堂。所以设置应该变成:

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)
    )

在此评论中,所有功劳都归尤金·布尔马科(Eugene Burmako)所有。

相关内容

  • 没有找到相关文章

最新更新