问题描述
我正在尝试编译一个Mscal Java/Scala混合项目,该项目具有一个Scala类,该类依赖于带有lombok批注的Java bean.我尝试将lombok jar文件以及lombok代理添加到Scala编译器的启动类路径中,但是编译器仍然无法找到生成的getter.Scala编译器是否可以识别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?
请注意,我试图避免仅仅为了首先编译该bean而引入另一个maven项目,因为该bean逻辑上属于同一项目.同样,我无法在Scala中重写该bean,因为以后将在GWT项目中使用它.
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.
谢谢
推荐答案
我认为您将无法避免.正常的Scala/Java集成的工作方式如下:
I think you'll not be able to avoid it. Normal Scala/Java integration works like this:
- Scala首先,因为Java对Scala一无所知.
- Scala goes first, since Java doesn't know anything about Scala.
- Scalac解析Java文件并了解可见元素.
- Scalac读取Scala文件并生成类文件.
一个明显的问题是Scala对Lombok批注一无所知,因此无法弄清楚它生成的元素.
The obvious problem is that Scala doesn't know anything about Lombok annotations, so it can't figure out the elements generated by it.
如果您没有从Java到Scala的任何依赖关系,则可以简单地颠倒顺序:让Java首先运行,让Scala在其类路径中包含javac的输出类文件.
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.
这篇关于编译Java/Scala混合项目和Lombok时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!