我试着在我的项目中加入宏注解,在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条答案
按热度按时间waxmsbnn1#
加
转换为
commonSettings
(Scala 2.11-2.12)。在Scala 2.13中,只需打开
scalacOptions += "-Ymacro-annotations"
Auto-Generate Companion Object for Case Class in Scala