Error compiling Java/Scala mixed project and Lombok

╄→гoц情女王★ 提交于 2021-02-04 13:24:25

问题


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,


回答1:


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.



来源:https://stackoverflow.com/questions/11171631/error-compiling-java-scala-mixed-project-and-lombok

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!