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.
Asked
Active
Viewed 3,008 times
1 Answers
5
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.

sourcedelica
- 23,940
- 7
- 66
- 74
-
I orginally tried this but I must have had a mistake in my pom. I started with a verbatim copy of the pom in the first link and it worked. It seems to work with either seperate or mixed source trees. Why do you recommend against combining scala and java in the same directory? – Shane Aug 30 '12 at 04:23
-
Because that's not the way that the plugin wants to work. If you can get it to work that's cool - let us know. But my recommendation is always going to be go with the flow... – sourcedelica Aug 30 '12 at 11:29
-
why isn't it a good idea to put java and scala code in the same directory? – gosua Mar 22 '16 at 18:57
-
I'd like to know why not, too. I would be grateful if you answer [my question](http://stackoverflow.com/questions/40106622) about this topic. – Ohashi Oct 22 '16 at 08:29