我正在尝试在我的项目中包含宏注释。关注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展开宏注释")
)。有什么想法吗?
最佳答案
添加
addCompilerPlugin("org.scalamacros" % "paradise" % "2.1.1" cross CrossVersion.full)
到 commonSettings
。
关于Scala 宏注解不会扩展(宏天堂),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55457246/