我可以使用混合的Java和Scala代码在Maven中以两种方式编译Scala项目? [英] Can I compile a Scala project with mixed java and scala code with dependencies both ways in Maven?
问题描述
通常的Maven目录结构是
src /
main /
java /
com / foo / mypackage /
scala /
com / foo / mypackage /
如果您以这种方式设置,那么肯定可以在Java和Scala代码之间建立交叉依赖关系。请参阅 maven-scala-plugin 或 scala-maven-plugin 页面上的主题。
我不建议将Java和Scala代码放在同一目录中。
I have a project which has both scala and java code which I am currently managing in eclipse using the scala IDE plugin. At present the directory structure is organized such that some packages have both java and scala code in them. There are scala classes which depend on java classes and there are other java classes which depend on the scala classes. The plugin handles all of this transparently – I believe (but I’m not 100% sure) that the scala compiler compiles both the java and scala code together which is how the cross dependencies are handled. I did find some references to compiling mixed projects using Maven e.g. here but the ones I saw talking about separating the java and scala into two separate source trees. Maven attempts to compile the scala code first which fails because of the dependencies on the java code. Likewise, if the java code were compiled first it would also fail as the dependencies go both ways. Is there a way to have Maven compile all the code together like the eclipse plugin? I’d also like to have the ability to generate an eclipse project without doing too much manual fix-up afterwards if possible.
The usual Maven directory structure is
src/
main/
java/
com/foo/mypackage/
scala/
com/foo/mypackage/
If you set things up this way then for sure you can have cross dependencies between your Java and Scala code. See the maven-scala-plugin or scala-maven-plugin pages on the topic.
I would not recommend putting Java and Scala code in the same directory.
这篇关于我可以使用混合的Java和Scala代码在Maven中以两种方式编译Scala项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!