在Maven项目中逐步编译Scala

时间:2015-10-16 00:26:03

标签: scala maven incremental-build scala-maven-plugin

我想在Maven项目中逐步编译Scala。

目前,即使 nothing 更改,Scala也会编译。

我已经尝试过scala-maven-plugin,但它似乎根本没有增量。

的pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0">
    <artifactId>example</artifactId>

    <build>
        <plugins>
            <plugin>
                <artifactId>scala-maven-plugin</artifactId>
                <configuration>
                    <recompileMode>incremental</recompileMode>
                    <scalaVersion>2.11.7</scalaVersion>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                </executions>
                <groupId>net.alchim31.maven</groupId>
                <version>3.2.2</version>
            </plugin>
        </plugins>
    </build>

    <groupId>example</groupId>

    <modelVersion>4.0.0</modelVersion>

    <name>example</name>

    <version>0.0-SNAPSHOT</version>
</project>

的src /主/阶/示例/ Foo.scala

package example

class Foo {
  val foo = None
}

Maven版本:

$ mvn --version
Apache Maven 3.2.1 (ea8b2b07643dbb1b84b6d16e1f08391b666bc1e9; 2014-02-14T10:37:52-07:00)
Maven home: /usr/share/maven3
Java version: 1.8.0_45-internal, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-openjdk-amd64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.13.0-65-generic", arch: "amd64", family: "unix"

然后:

$ mvn compile
[INFO] Scanning for projects...
[INFO] 
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building example 0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ example ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/paul/dev/example/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ example ---
[INFO] No sources to compile
[INFO] 
[INFO] --- scala-maven-plugin:3.2.2:compile (default) @ example ---
[INFO] Using incremental compilation
[INFO] Compiling 1 Scala source to /home/paul/dev/example/target/classes...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.090 s
[INFO] Finished at: 2015-10-15T18:22:34-07:00
[INFO] Final Memory: 23M/412M
[INFO] ------------------------------------------------------------------------
$ mvn compile
[INFO] Scanning for projects...
[INFO] 
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building example 0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ example ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/paul/dev/stash-conditions-test/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ example ---
[INFO] No sources to compile
[INFO] 
[INFO] --- scala-maven-plugin:3.2.2:compile (default) @ example ---
[INFO] Using incremental compilation
[INFO] Compiling 1 Scala source to /home/paul/dev/stash-conditions-test/target/classes...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.661 s
[INFO] Finished at: 2015-10-15T18:22:39-07:00
[INFO] Final Memory: 23M/418M
[INFO] ------------------------------------------------------------------------

每次编译!

如果只有在Scala发生变化时才能获得编译Scala的Maven项目?

1 个答案:

答案 0 :(得分:1)

你应该尝试: mvn scala:cc 。 请参阅此处的说明http://davidb.github.io/scala-maven-plugin/example_cc.html