简体   繁体   English

Maven 是否支持增量构建?

[英]Does Maven support incremental builds?

How does one use Maven to support incremental builds?如何使用 Maven 来支持增量构建? Is there a guide somewhere?某处有指南吗? (top Google results are disappointing) (谷歌搜索结果令人失望)

I can't quite figure out the dynamic that drives the Maven community but it isn't one that's friendly to having fine-grained control over your build-process. 我无法弄清楚驱动Maven社区的动态,但对于对构建过程进行细粒度控制并不友好。

Anyhow, after digging around I found an answer that worked for me here: http://www.codesenior.com/en/tutorial/Java-Maven-Compile-Only-Changed-Files 无论如何,在挖掘之后我找到了一个对我有用的答案: http//www.codesenior.com/en/tutorial/Java-Maven-Compile-Only-Changed-Files

Note that setting the value to false confused me at first, but an explanation is given here: https://stackoverflow.com/a/19653164/409638 请注意,首先将值设置为false会使我感到困惑,但此处给出了解释: https//stackoverflow.com/a/19653164/409638

Reproduced here for convenience: 为方便起见,这里转载:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.2</version>
    <configuration>
        <source>1.6</source>
        <target>1.6</target>
        <useIncrementalCompilation>false</useIncrementalCompilation>
    </configuration>
</plugin>

It's the useIncrementalCompilation set to false that is key here. 这是useIncrementalCompilation设置为false ,这是关键。

I can confirm that when I run my build I have gone from: 我可以确认,当我运行我的构建时,我已经离开:

[INFO] Changes detected - recompiling the module!
[INFO] Compiling 114 source files to /home/vagrant/workspace/splat/target/classes

to

[INFO] Compiling 1 source file to /home/vagrant/workspace/splat/target/classes

which has shaved a few seconds of my incremental build. 这削减了我的增量构建的几秒钟。 Now all I've got to do is figure out how to disable all the other unnecessary cruft that's slowing down my edit/evaluate cycles ... 现在我所要做的就是弄清楚如何禁用所有其他不必要的错误,这会减慢我的编辑/评估周期......

Maven builds incrementally by default, but it turns out that the compiler plugin (ie, the core of javac) is so fast that building fresh every time is not a bottleneck with sane codebase sizes, not by comparison with constructing large assemblies or running large test suites. 默认情况下,Maven逐步构建,但事实证明编译器插件(即javac的核心)是如此之快以至于每次构建新鲜都不是代码库大小合理的瓶颈,而不是与构建大型程序集或运行大型测试相比套房。 (Java, like most languages, is much faster to compile than C++.) (与大多数语言一样,Java的编译速度比C ++快得多。)

You can use the maven-incremental build plugin , if your project has hundreds of modules. 如果您的项目有数百个模块,则可以使用maven-incremental构建插件 It saves lot of time. 它节省了大量时间。

Takari Maven Lifecycle Takari Maven生命周期

Yes, it is possible now thanks to takari-lifecycle-plugin . 是的,现在可以感谢takari-lifecycle-plugin了 Take look at this sample project: maven-incremental-compilation 看一下这个示例项目: maven-incremental-compilation

Sample output 样本输出

[INFO] --- takari-lifecycle-plugin:1.10.2:compile (default-compile) @ maven-incremental-compilation ---
[INFO] Performing incremental build
[INFO] Compiling 2 sources to /home/mariuszs/maven-incremental-compilation/target/classes
[INFO] Compiled 1 out of 2 sources (670 ms)

More information 更多信息

Maven supports building subsets of multi module projects using the command line arguments -pl , -am and -amd to specify modules to build, also build dependencies and also build dependents, respectively. Maven支持使用命令行参数-pl-am-amd构建多模块项目的子集,以指定要构建的模块,还分别构建依赖项和构建依赖项。 It will also only compile changed source files in any given module (not really a Maven feature so much as a javac feature). 它也只会在任何给定模块中编译已更改的源文件(实际上不是maven功能,而是javac功能)。

Update: truly incremental build support - similar to one in Gradle - has made it in Maven code base.更新:真正的增量构建支持——类似于 Gradle 中的支持——已经在 Maven 代码库中实现。 Introduction video is here: https://youtu.be/DEQG4CNFMFE介绍视频在这里: https : //youtu.be/DEQG4CNFMFE

Though maven core doesnt support caching so far, you can check this PR - it is a real incremental build with support for remote cache.虽然到目前为止 maven 核心不支持缓存,但您可以查看这个 PR - 它是一个真正的增量构建,支持远程缓存。 It also support literally all plugins - https://github.com/apache/maven/pull/526它还支持所有插件 - https://github.com/apache/maven/pull/526

You can build and try maven from the branch and enjoy.您可以从分支构建和尝试 maven 并享受。 We are working to bring caching in a form of core extension into Maven我们正在努力将缓存以核心扩展的形式引入 Maven

Kind regards Alex亲切的问候亚历克斯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM