3

Is it possible to have a Scala Maven project and weave AspectJ aspects at compile-time within the Scala classes?

I've been able to get load-time weaving to work but so far no success with compile-time.

The aspects are simply not woven into the Scala classes. From what I understand, compile-time weaving requires a specific Java compiler (AspectJ Compiler aka ajc). It is my understanding that ajc cannot compile Scala.

Is there an ajc equivalent for Scala? Or perhaps another way to get compile-time weaving to work with Scala?

GuiSim
  • 7,361
  • 6
  • 40
  • 50
  • more info needed. Are you getting errors, or just not seeing behavior you expect to be woven in? You could post some of your artifacts. – Ladlestein Dec 04 '12 at 03:20
  • I've added details. I'm not getting errors and the aspects are not woven. This is expected though as I fail to see how it _should_ work at all. I don't see how I could configure AspectJ Compiler to compile Scala and inject aspects within the Scala bytecode. – GuiSim Dec 04 '12 at 15:22

2 Answers2

2

Answer 1 isn't true compile-time weaving - it's binary weaving of already-compiled classes. It wouldn't work, for instance, if your scala classes needed the aspects to compile properly. I think the issue of compile-time weaving in scala is still an open question.

We agree with the assessment by the original poster that ajc is unlikely to know how to compile scala.

SteveK
  • 461
  • 4
  • 7
1

How about using AJC's -inpath switch? It accepts .class files in directories or JARs and weaves into them. Your Scala compiles to .class files, so that ought to work. No doubt you have the AJC docs, but here's a link.

Ladlestein
  • 6,100
  • 2
  • 37
  • 49
  • I was able to get this to work using aspectj-maven-plugin's "weaveDirectory" parameter (which maps to ajc's -inpath). Thanks! – GuiSim Mar 04 '13 at 13:46