Macros annotation not working in IntelliJ14

1.7k Views Asked by At

I am having trouble using Scala Macros. It keeps on telling me to

enable macro paradise to expand macro annotations

from the @compileTimeOnly message I wrote. I followed all the instructions from Macro annotation documentation and the SBT example.

IDE: IntelliJ 14.1

Scala version: 2.11.7

Build.scala under the Project folder:

import sbt._
import sbt.Keys._

object Build extends Build {
  val paradiseVersion = "2.1.0-M5"
  lazy val sm = Project(id = "server-modules", base = file(".")).settings(
    version := "1.0",
    logLevel := Level.Warn,
    scalacOptions ++= Seq(),
    scalaVersion := "2.11.7",
    crossScalaVersions := Seq("2.10.2", "2.10.3", "2.10.4", "2.10.5", "2.11.0", "2.11.1", "2.11.2", "2.11.3", "2.11.4", "2.11.5", "2.11.6", "2.11.7"),
    resolvers += Resolver.sonatypeRepo("snapshots"),
    resolvers += Resolver.sonatypeRepo("releases"),
    addCompilerPlugin("org.scalamacros" % "paradise" % paradiseVersion cross CrossVersion.full),
    libraryDependencies <+= (scalaVersion)("org.scala-lang" % "scala-reflect" % _),
  )
}

Code:

@compileTimeOnly("enable macro paradise to expand macro annotations")
class dmCompile extends StaticAnnotation{
  def macroTransform(annottees: Any*): Any = macro DMCompile.impl
}

object DMCompile {
  def impl(c: whitebox.Context)(annottees: c.Expr[Any]*): c.Expr[Any] = {
    import c.universe._

    Log.info("Work work work!")

    c.Expr(q"""var x = y""")
  }
}

@dmCompile class Test{}

What exactly am I missing?

2

There are 2 best solutions below

0
On BEST ANSWER

This took me the entire day, but I got it working.

Simply disregard the SBT settings for macros paradise and manually add it in the Preference -> Scala Compiler

enter image description here

That's it!

0
On

For me a solution was to change Incrementality type from IDEA to SBT in the Settings. This allows to use native SBT's build engine instead of IDEA's one.

IDEA settings screenshot