Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error compiling Java/Scala mixed project and Lombok

I am trying to compile a Maven Java/Scala mixed project that has a Scala class that depends on a Java bean with lombok annotations. I tried adding the lombok jar file to the boot classpath of the Scala compiler as well as the lombok agent, but the compiler still failed to find the generated getters. Is there a way for the Scala compiler to recognize the lombok annotations? If not, what would be a good workaround?

Pease note that I am trying to avoid introducing another maven project just for compiling this bean first as the bean logically belongs to the same project. Also I cannot rewrite the bean in Scala as it is later used in a GWT project.

Thank you,

like image 352
Eduardo Avatar asked Jun 23 '12 17:06

Eduardo


1 Answers

I think you'll not be able to avoid it. Normal Scala/Java integration works like this:

  1. Scala goes first, since Java doesn't know anything about Scala.
    1. Scalac parsers Java files and learns about visible elements.
    2. Scalac reads Scala files and generate class files.
  2. Java goes last, and reads Java files plus the class files generated by Scala.

The obvious problem is that Scala doesn't know anything about Lombok annotations, so it can't figure out the elements generated by it.

If you don't have any dependency from Java to Scala, you can simply invert the order: let Java go first, and have Scala include the output classfiles of javac on its classpath.

Otherwise, I suppose you'll need to break it up.

like image 173
Daniel C. Sobral Avatar answered Oct 18 '22 14:10

Daniel C. Sobral