Issue
There are some existing similar questions based on codes, but I want to ask in a more general way.
Suppose there are java source code and scala source code, seems scala-maven-plugin
is to be added.
- So is there a default config which one is compiled first, scala or java?
- If we want scala code depends on java, or the opposite, how to do it? (like
scala-compile-first
in plugin?) - Is is possible that some scala code depends on java, while some java code also depends on scala?
Solution
- java is compiled first, if both compilation are run in their default phase
- scala depends of java, nothing to customize, it's the default behavior. If java depends of scala you should force the compilation of scala code during a phase before like
process-resources
. - Yes you can have "mixed" scala/java, in this case scala compiler should run before and be aware of java source (the scala compiler will parse them to extract API). It's the same configuration than scala first
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
...
For example see the docs: Mixed Java/Scala Projects – scala-maven-plugin or the integration test scala-maven-plugin/src/it at master · davidB/scala-maven-plugin
Answered By - David Bernard