解决 SBT 中 Scala 宏和编译器框架的依赖 [英] Resolving the dependency of Scala Macros and Compiler Framework in SBT

查看:63
本文介绍了解决 SBT 中 Scala 宏和编译器框架的依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个框架,以便更轻松地编写 Scala 编译器插件,我正在做的是在 Scala quasiquotes 之上编写一个框架.所以我的项目依赖于来自宏天堂的宏以及 Scala 编译器和 Scala 反射库.

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.

我按照此处提到的说明编写了 SBT 构建脚本:https://github.com/scalamacros/sbt-example-paradise/blob/master/project/Build.scala

I wrote an SBT build script by following the instructions mentioned here: 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 构建脚本:

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

使用 scalaVersion 2.10-3-RC1,我收到以下错误:

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) 

使用 scalaVersion 2.11.0-SNAPSHOT,我收到以下错误:

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)

在使用 2.10.3-SNAPSHOT 版本时,我得到以下信息:

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

2.10.2 版本根本无法解决 scala-library、scala-reflect 和 2.10.2 的依赖关系(如 2.10.3-RC1)!

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

我的问题是,是否有可能混合编译器 API 和宏 API 并使它们在 SBT 下工作,如果是,我的构建脚本到底有什么问题?

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?

推荐答案

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

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

所有学分归Eugene Burmako 在此评论.

这篇关于解决 SBT 中 Scala 宏和编译器框架的依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆