如何配置我的 Maven-war-plugin 的 useCache 功能,以便连续构建更快?
How do I configure my Maven-war-plugin's useCache feature so that consecutive builds are faster?
我在 Mac Yosemite 上使用 Maven 3.3.0。我想利用 maven-war-plugin 的 useCache
功能,但它在我的多模块项目中没有做任何事情。当我运行
mvn clean install -DskipTests
我的项目使用以下配置 1:25 到 运行
<profile>
<id>prepare-deploy-war-to-jboss</id>
<activation>
<file>
<exists>${basedir}/src/main/webapp</exists>
</file>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<useCache>true</useCache>
<cacheFile>/tmp/${project.artifactId}/war/work</cacheFile>
</configuration>
</plugin>
</plugins>
</build>
</profile>
然后我 运行 再次执行相同的命令,该项目花费相同的时间。我可以看到正在创建“工作”文件,因此插件肯定 运行ning 但连续构建似乎没有做任何事情。
我的问题不是为什么 useCache
不能加快我的构建速度,而是我如何以不同的方式配置我的插件,以便连续的 运行 确实加快构建速度?如果有另一个我应该使用的插件可以加速背靠背 运行s 的构建,那么这里也足够了。
查看 WAR mojo code (at the time of writing), the cache is mainly used by its web app structure concerning overlays management,因此在大多数情况下它确实不会缩短构建时间。
此外,正如 its official documentation 所述,缓存机制是一项 实验性 功能,因此默认情况下禁用,这可能尚未达到(尚未)用户期望.
不管这个缓存选项的有效性如何,一些加速 maven 构建的提示可能是:
- 考虑是否真的需要
clean
每次 运行
- 如果您需要的一切都已在本地缓存中,请考虑离线构建(
-o
选项)
- 考虑在构建期间使用线程(
-T
选项)
- 考虑继续使用安静模式(
-q
选项),暂时关闭构建日志并仅获取错误日志(基本上:没有消息,好消息)
- 在您的情况下,War 插件在存在典型的
war
包装结构时被激活,这可能意味着此配置文件是 aggregator/parent pom 的一部分,并且然后仅在 war 模块上激活。虽然可能影响很小,但也可以考虑将 War 插件配置移动到其相关模块并避免这种触发配置
最后但同样重要的是,在开发期间,构建时间可能比 war 大小更重要,因此您可以关闭 default 重新压缩机制通过 recompressZippedFiles
选项将外部库添加到 war 文件:
Indicates if zip archives (jar,zip etc) being added to the war should be compressed again. Compressing again can result in smaller archive size, but gives noticeably longer execution time.
Default: true
因此示例配置如下所示:
<properties>
<war.recompress.files>false</war.recompress.files>
</properties>
<build>
<finalName>webapp</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<recompressZippedFiles>${war.recompress.files}</recompressZippedFiles>
</configuration>
</plugin>
</plugins>
</build>
注意:由于此配置条目没有用户 属性,我还为其添加了一个 属性,以通过命令行(或通过个人资料)。
然后您可以针对先前的配置(下面,根据需要为当前执行打开重新压缩)测试执行默认构建(上面的配置禁用重新压缩)的不同执行时间:
mvn clean install -Dwar.recompress.files=true
然后您可以考虑 profile it 根据开发阶段切换它 on/off。
我在 Mac Yosemite 上使用 Maven 3.3.0。我想利用 maven-war-plugin 的 useCache
功能,但它在我的多模块项目中没有做任何事情。当我运行
mvn clean install -DskipTests
我的项目使用以下配置 1:25 到 运行
<profile>
<id>prepare-deploy-war-to-jboss</id>
<activation>
<file>
<exists>${basedir}/src/main/webapp</exists>
</file>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<useCache>true</useCache>
<cacheFile>/tmp/${project.artifactId}/war/work</cacheFile>
</configuration>
</plugin>
</plugins>
</build>
</profile>
然后我 运行 再次执行相同的命令,该项目花费相同的时间。我可以看到正在创建“工作”文件,因此插件肯定 运行ning 但连续构建似乎没有做任何事情。
我的问题不是为什么 useCache
不能加快我的构建速度,而是我如何以不同的方式配置我的插件,以便连续的 运行 确实加快构建速度?如果有另一个我应该使用的插件可以加速背靠背 运行s 的构建,那么这里也足够了。
查看 WAR mojo code (at the time of writing), the cache is mainly used by its web app structure concerning overlays management,因此在大多数情况下它确实不会缩短构建时间。
此外,正如 its official documentation 所述,缓存机制是一项 实验性 功能,因此默认情况下禁用,这可能尚未达到(尚未)用户期望.
不管这个缓存选项的有效性如何,一些加速 maven 构建的提示可能是:
- 考虑是否真的需要
clean
每次 运行 - 如果您需要的一切都已在本地缓存中,请考虑离线构建(
-o
选项) - 考虑在构建期间使用线程(
-T
选项) - 考虑继续使用安静模式(
-q
选项),暂时关闭构建日志并仅获取错误日志(基本上:没有消息,好消息) - 在您的情况下,War 插件在存在典型的
war
包装结构时被激活,这可能意味着此配置文件是 aggregator/parent pom 的一部分,并且然后仅在 war 模块上激活。虽然可能影响很小,但也可以考虑将 War 插件配置移动到其相关模块并避免这种触发配置
最后但同样重要的是,在开发期间,构建时间可能比 war 大小更重要,因此您可以关闭 default 重新压缩机制通过 recompressZippedFiles
选项将外部库添加到 war 文件:
Indicates if zip archives (jar,zip etc) being added to the war should be compressed again. Compressing again can result in smaller archive size, but gives noticeably longer execution time.
Default:true
因此示例配置如下所示:
<properties>
<war.recompress.files>false</war.recompress.files>
</properties>
<build>
<finalName>webapp</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<recompressZippedFiles>${war.recompress.files}</recompressZippedFiles>
</configuration>
</plugin>
</plugins>
</build>
注意:由于此配置条目没有用户 属性,我还为其添加了一个 属性,以通过命令行(或通过个人资料)。
然后您可以针对先前的配置(下面,根据需要为当前执行打开重新压缩)测试执行默认构建(上面的配置禁用重新压缩)的不同执行时间:
mvn clean install -Dwar.recompress.files=true
然后您可以考虑 profile it 根据开发阶段切换它 on/off。