Can I compile a Scala project with mixed java and scala code with dependencies both ways in Maven?

痴心易碎 提交于 2019-12-04 21:09:02

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/12189078/can-i-compile-a-scala-project-with-mixed-java-and-scala-code-with-dependencies-b

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