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

问题描述 投票:1回答:1

我正在尝试在我的项目中包含宏注释。继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"))。有什么想法吗?

scala compilation macros annotations sbt
1个回答
0
投票

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

commonSettings

© www.soinside.com 2019 - 2024. All rights reserved.