mixed scala/java project, which compile first?

1.1k Views Asked by At

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.

  1. So is there a default config which one is compiled first, scala or java?
  2. If we want scala code depends on java, or the opposite, how to do it? (like scala-compile-first in plugin?)
  3. Is is possible that some scala code depends on java, while some java code also depends on scala?
1

There are 1 best solutions below

1
On BEST ANSWER
  1. java is compiled first, if both compilation are run in their default phase
  2. 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.
  3. 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