Scala宏注释不会扩展(宏天堂)

时间:2019-04-01 14:14:23

标签: scala compilation macros annotations sbt

我正在尝试在项目中包含宏注释。在documentation之后,我尝试实现他们的示例。

我知道宏模块必须在核心模块(核心是包含利用宏注释的代码的模块)之前进行编译。为此,我创建了以下build.sbt(1.2.8版):

name := "test"

lazy val commonSettings = Seq(
  version := "0.1",
  scalaVersion := "2.12.8"
)

lazy val macros = (project in file("macros")).settings(
  commonSettings,
  libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaVersion.value
)

lazy val core = (project in file("core")).settings(
  commonSettings
) dependsOn macros

我的项目的结构如下:

+-- .idea
+-- core
|   +-- src
|   |   +-- java
|   |   +-- scala
|   |   |   +-- Test.scala
+-- macros
|   +-- src
|   |   +-- java
|   |   +-- scala
|   |   |   +-- identity.scala
...

但是,当我在Test类中使用@identity注释时,仍然收到消息,指出宏注释未展开(由于@compileTimeOnly("enable macro paradise to expand macro annotations"))。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

添加

addCompilerPlugin("org.scalamacros" % "paradise" % "2.1.1" cross CrossVersion.full)

commonSettings