Tuesday, 10 September 2013

Issue with using Macros in SBT

Issue with using Macros in SBT

Assume you have two SBT projects, one called A and another called B
A has a subproject called macro, that follows the exact same pattern as
showed here
(http://www.scala-sbt.org/0.13.0/docs/Detailed-Topics/Macro-Projects.html).
In other words, A has a subproject macro with a package that exposes a
macro (lets called it macrotools). Now both projects, A and B, use the
macrotools package (and A and B are strictly separate projects, B uses A
via dependancies in SBT, with A using publish-local)
Now, A using A's macrotools package is fine, everything works correctly.
However when B uses A macrotools package, the following error happens
java.lang.IllegalAccessError: tried to access method
com.monetise.waitress.types.Married$.<init>()V from class
com.monetise.waitress.types.RelationshipStatus$
For those wondering, the macro is this one
http://stackoverflow.com/a/13672520/1519631, so in other words, this macro
is what is inside the macrotools package
This is also related to my earlier question Macro dependancy appearing in
POM/JAR, except that I am now using SBT 0.13, and I am following the
altered guide for SBT 0.13
The code being referred to above is, in this case, this is what is in B,
and A is com.monetise.incredients.macros.tools (which is a dependency
specified in build.sbt)
package com.monetise.waitress.types
import com.monetise.ingredients.macros.tools.SealedContents
sealed abstract class RelationshipStatus(val id:Long, val
formattedName:String)
case object Married extends RelationshipStatus(0,"Married")
case object Single extends RelationshipStatus(1,"Single")
object RelationshipStatus {
// val all:Set[RelationshipStatus] = Set(
// Married,Single
// )
val all:Set[RelationshipStatus] = SealedContents.values[RelationshipStatus]
}
As you can see, when I use whats commented, the code works fine (the job
of the macro is to fill the Set with all the case objects in an ADT). When
I use the macro version, i.e. SealedContents.values[RelationshipStatus] is
when I hit the java.lang.IllegalAccessError

No comments:

Post a Comment