Incremental Compile

Incremental compilation is supported using Zinc, sbt's embedded incremental compiler.

Setup

The incremental compilation is enabled by default after scala-maven-plugin v4.0.0, and the "recompileMode" configuration option is set to "incremental" by default. You can also configure the `recompileMode` configuration to `all` to disable the incremental comiler. For example:

        
<project>
  ...
  <plugin>
    <groupId>net.alchim31.maven</groupId>
    <artifactId>scala-maven-plugin</artifactId>
    <version>4.4.1</version>
    <configuration>
      <recompileMode>incremental</recompileMode>
    </configuration>
  </plugin>
  ...
</project>
        
      

Increasing Memory

Increasing memory for incremental compilation is different from regular compiles where the "jvmArgs" option is used. The incremental compiler does not fork a separate process for compilation, so increasing memory is done by increasing the memory for the Maven process. This can be done via the "MAVEN_OPTS" environment variable.

Mixed Scala and Java Sources

The incremental compiler will compile both Scala and Java sources, rather than deferring to the Maven Compiler Plugin for Java compilation. It does this so that analyses for both Scala and Java sources are calculated, giving incremental compilation across all sources.

To configure a project with mixed Scala and Java sources with incremental compilation, the Scala Maven Plugin should always compile before the Maven Compiler Plugin. See the examples for Mixed Java/Scala Projects.

Any javac arguments must be configured for the Scala Maven Plugin, rather than the Maven Compiler Plugin, and are configured with the "javacArgs" configuration option, similar to the "args" option for scalac options. For example:

        
<project>
  ...
  <plugin>
    <groupId>net.alchim31.maven</groupId>
    <artifactId>scala-maven-plugin</artifactId>
    <version>4.4.1</version>
    <configuration>
      <recompileMode>incremental</recompileMode>
      <javacArgs>
        <javacArg>-Xlint:unchecked</javacArg>
        <javacArg>-Xlint:deprecation</javacArg>
      </javacArgs>
    </configuration>
  </plugin>
  ...
</project>
        
      

The incremental compiler will by default handle mixed compile order for Scala and Java sources. That is, Scala and Java sources can depend on each other. If you have a specific order, Scala depending on Java, or Java depending on Scala, then you can specify the compile ordering to use with the "compileOrder" configuration option. Possible values are "Mixed" (the default), "JavaThenScala" (alternatively "java-then-scala" or just "java"), and "ScalaThenJava" (alternatively "scala-then-java" or just "scala").

Analysis Cache

The incremental compiler creates an extra output file per compilation. This is a cache of the analysis information required by the incremental compiler, used to determine which files to compile after changes. If you set a custom output directory in your project then you may also want to set the location of the analysis cache file. You can do this with the "analysisCacheFile" and "testAnalysisCacheFile" configuration options. For example:

        
<project>
  ...
  <plugin>
    <groupId>net.alchim31.maven</groupId>
    <artifactId>scala-maven-plugin</artifactId>
    <version>4.4.1</version>
    <configuration>
      <recompileMode>incremental</recompileMode>
      <analysisCacheFile>path/to/analysis-cache-file</analysisCacheFile>
      <testAnalysisCacheFile>path/to/test-analysis-cache-file</testAnalysisCacheFile>
    </configuration>
  </plugin>
  ...
</project>