注意 - 我在Stackoverflow上看到了关于scala宏扩展的其他帖子,大多数解决方案都集中在使用SBT。我也想用scalac解决它,检查生成的代码。因此发布一个类似且可能重复的问题。
我可以使用SBT或使用Scala-IDE来使用宏。我正在尝试使用以下Scala-lang文档中的详细信息来检查宏代码: https://docs.scala-lang.org/overviews/macros/overview.html#inspecting-generated-code
获取宏扩展失败错误:
scalac -language:experimental.macros -classpath "/Users/kalyana/.m2/repository/me/ganaakruti/runtime/gboxruntime_2.12/0.1/gboxruntime_2.12-0.1.jar" -Dscala.usejavacp=true -Ymacro-debug-lite src/main/scala/me/ganaakruti/conversational/pipes/gBoxTryBenchmark.scala
src/main/scala/me/ganaakruti/conversational/pipes/gBoxTryBenchmark.scala:8: error: 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)
def methodWithArguments(a: Double, b: Double) = {
^
one error found
下面是使用sbt runMain:
成功运行同一个宏sbt "runMain me.ganaakruti.conversational.pipes.gBoxTryBenchmark"
[info] Loading project definition from /cdev/cbase/gboxcore/gBoxConversationalPipes/project
[info] Set current project to gBoxConversationalPipes (in build file:/cdev/cbase/gboxcore/gBoxConversationalPipes/)
[warn] Multiple main classes detected. Run 'show discoveredMainClasses' to see the list
[info] Running me.ganaakruti.conversational.pipes.gBoxTryBenchmark
[info] methodWithArguments elapsed time: 25255ns
[success] Total time: 1 s, completed Nov 28, 2017 3:33:29 PM
有什么想法吗?
宏实现在一个单独的sbt项目中。我已经将项目发布到本地.m2并在我的实现中引用了宏项目jar,我正在尝试宏扩展。
Scala版本 - 12.2.3 sbt.version = 0.13.16