2

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

目前,即使没有任何变化,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/main/scala/example/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 项目?

4

2 回答 2

1

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

于 2015-11-11T10:07:35.447 回答
0

需要all通过incremental

<configuration>
    <recompileMode>all</recompileMode>
</configuration>
于 2021-12-15T09:53:41.460 回答