【发布时间】:2019-04-14 13:25:23
【问题描述】:
我使用cats-tagless lib 创建了一个简单的trait:
@finalAlg
@autoFunctorK(true)
trait MyService[F[_]] {
def put(element: Element): F[Element]
def get(elementId: Id): F[Element]
def all(): F[List[Element]]
def delete(elementId: Id): F[Unit]
}
但是当我尝试编译它时,我得到了一个错误:
Error:(8, 7) macro annotation could not be expanded (the most common reason for that is that you need to enable the macro paradise plugin; another possibility is that you try to use macro annotation in the same compilation run that defines it)
我还将addCompilerPlugin("org.scalamacros" % "paradise" % "2.1.1" cross CrossVersion.full) 添加到plugins.sbt 文件和build.sbt 中,但没有帮助。你能帮我解决吗?
我的build.sbt 文件如下所示:
addCompilerPlugin(("org.scalameta" % "paradise" % "3.0.0-M11").cross(CrossVersion.full))
lazy val commonSettings = Seq(
libraryDependencies ++= Seq(
"org.typelevel" %% "cats-core" % CatsVersion,
"org.typelevel" %% "cats-effect" % "1.2.0",
"org.typelevel" %% "cats-tagless-macros" % "0.5",
"org.typelevel" %% "cats-tagless-legacy-macros" % "0.5",
"org.typelevel" %% "cats-mtl-core" % "0.5.0",
)
)
【问题讨论】:
-
什么是
CatsVersion? -
目前为 1.6.0
-
是的,我在模块
algebra中使用它,在那里我创建了服务trait。像这样使用它lazy val algebra = (project in file("algebra")) .settings(commonSettings)
标签: scala scala-macros scala-cats scala-macro-paradise