[英]Configuring Gradle to speed up cordova-cli builds
I use Cordova CLI to build my hybrid Android app. 我使用Cordova CLI构建我的混合Android应用。 In my effort to speed up compile times I have moved the entire Android installation to an SSD and upgraded my machine with an extra 8Gb of memory (total of 16Gb).
为了加快编译速度,我将整个Android安装都移至SSD上,并为机器升级了额外的8Gb内存(总共16Gb)。 Nevertheless I see zero effect on compile times which are stuck at pretty much the same figure as they were prior to these upgrades.
不过,我发现对编译时间的影响为零,几乎与升级之前的数字相同。 I am starting to suspect that it is not enough to merely provide more resources.
我开始怀疑仅仅提供更多的资源是不够的。 Somehow Gradle needs to be told to use them.
需要以某种方式告诉Gradle使用它们。 However, I am not sure how I do this within the context of a hybrid Cordova app.
但是,我不确定如何在混合Cordova应用程序的上下文中执行此操作。
Acting on the ideas I found in this Reddit thread I created a gradle.properties
file in the app/platforms/android
folder where I put 根据我在Reddit线程中发现的想法,我在
gradle.properties
了app/platforms/android
文件夹中创建了gradle.properties
文件
org.gradle.parallel=true
org.gradle.daemon=true
org.gradle.configureondemand=true
org.gradle.jvmargs=-Xms2048m -Xmx8096m -XX:PermSize=1024
-XX:MaxPermSize=1024m -XX:ReservedCodeCacheSize=1024m
This did have an effect - it made the build almost 50% slower! 这确实有效果-它使构建速度降低了近50%! The first build with a new Gradle daemon is usually slower so I recompiled.
通常,使用新的Gradle守护程序进行的首次构建速度会较慢,因此我需要重新编译。 There was a small saving but the build was still slower than before.
节省了一点钱,但是构建仍然比以前慢。 Clearly, there is more to configuring Gradle than telling it to use tons of memory.
显然,配置Gradle不仅仅是告诉它使用大量内存。 However, I have no experience in the domain.
但是,我没有相关领域的经验。 Could someone here tell me how I should go about the process in order to get some real performance benefits?
有人可以告诉我我应该如何进行该过程,以获得真正的性能收益?
I was recently working on tuning Jenkins pipelines and migrating an app from Maven to Gradle so I hope my knowledge might be useful. 我最近正在调整Jenkins管道,并将应用程序从Maven迁移到Gradle,所以我希望我的知识可能有用。
First of all, you can measure difference in execution time in the following way: 首先,您可以通过以下方式衡量执行时间的差异:
.gradle
folders. .gradle
文件夹。 It is Gradle's cache folders and it might be accidentally used. gradle --stop
. gradle --stop
。 It will stop Gradle daemons so that no cache in daemons itself can be used. gradle clean build
gradle clean build
Secondly, the gain that you've got is mostly due to using org.gradle.parallel=true
. 其次,您获得的收益主要归功于使用
org.gradle.parallel=true
。 You may try to remove other things and I bet there will be no significant change in performance. 您可以尝试删除其他内容,但我敢保证性能不会发生重大变化。
org.gradle.daemon=true
is the default value for the option. org.gradle.daemon=true
是该选项的默认值。 Also, I would revise JVM flags as eg -XX:MaxPermSize
is not used in Java 8 (although I understand you're working on Android app) 另外,我会修改JVM标志,例如
-XX:MaxPermSize
未在Java 8中使用(尽管我了解您正在使用Android应用程序)
Thirdly, regarding speeding up the compilation itself, you can use this flags: 第三,关于加快编译本身,可以使用以下标志:
GRADLE_OPTS="-XX:+TieredCompilation -XX:TieredStopAtLevel=1"
It should turn off JVM profiling so it might do the trick for you. 它应该关闭JVM性能分析,以便为您解决问题。
Thirdly, check compile
vs implementation
. 第三,检查
compile
与implementation
。 Using of implementation
configuration theoretically may speed up compilation and recompilation process because of not using transitive dependencies. 理论上,由于不使用传递依赖项,因此使用
implementation
配置可以加快编译和重新编译过程。
I guess I don't know other ways to speed up compilation of a Gradle project. 我想我不知道其他方法可以加快Gradle项目的编译速度。 However, there are things like parallel test execution if you're interested in speeding up the whole build.
但是,如果您有兴趣加快整个构建的速度,可以使用并行测试执行之类的方法。
The last note: check you plugins. 最后一点:检查您的插件。 Sometimes they do useless things you don't really need (mine bottleneck was
wsdl2java
) eg copying many unused generated sources. 有时它们会执行您真正不需要的无用的工作(瓶颈是
wsdl2java
),例如复制许多未使用的生成的源。
Hope it helps! 希望能帮助到你!
Move your project's build folder to SSD: there are tons of write operations during build and write is always much slower than read. 将项目的构建文件夹移动到SSD:在构建过程中有大量的写操作,写操作总是比读操作慢得多。
And configure antivirus software (if any) to exclude all java binaries, project's build folder and ~/.gradle from scanning. 并配置防病毒软件(如果有)以从扫描中排除所有Java二进制文件,项目的构建文件夹和〜/ .gradle。
These two actions should be enough to see the difference. 这两个动作应该足以看出差异。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.