我是一个相对较新的gradle和Play。
我正在使用gradle作为构建系统的play项目。我尝试使用构建缓存来获得更好的性能。从构建扫描,我观察' compilePlayBinaryScala'不可缓存,大多数其他任务都依赖于' compilePlayBinaryScala'。为' compilePlayBinaryScala'启用缓存将真正扩大构建。
Gradle官方文档列出了.*PlayBinary
个任务(https://docs.gradle.org/current/userguide/play_plugin.html)
我找不到' compilePlayBinaryScala'的明确任务定义。或任何其他.*PlayBinaryScala
任务。这些任务在哪里定义?
从我的研究中,我可以看到这个文件可以创建任务。但是,我不确定。 https://github.com/gradle/gradle/blob/de399b5015b19c07d94aa2eabec47709fc719a68/subprojects/platform-play/src/main/java/org/gradle/play/plugins/PlayApplicationPlugin.java#L160
因为我是新手详细解释为什么这样做会非常有帮助。
答案 0 :(得分:1)
任务在该文件中创建,但不在您链接的方法中创建。在createScalaCompileTask
,createJarTasks
,createPlayRunTask
等方法中为每个二进制文件创建任务。 @Mutate
,@BinaryTasks
,`@ ComponentBinaries是Gradle中称为基于规则的模型(也是软件模型)的一部分。用法在Play plugin documentation中描述。 Gradle团队试用了这个模型几年,但最终决定反对它并且没有正式弃用(参见博客文章State and future of the Gradle Software Model。
compilePlayBinaryScala
的类型为PlatformScalaCompile
。这在文档中说明,也可以通过运行./gradlew model
或添加类似日志的任务操作来确定。 "compilePlayBinaryScala"
的任务名称是根据插件的一部分计算得出的。组件名称为"play"
,因此二进制文件和任务是基于该目标和目标平台生成的。如果插件支持多于1个平台(在撰写本文时没有),任务命名约定将更加明显。另一个基于组件名称生成任务的插件示例是Gradle' native support。
关于规则模型是如何构建的,不值得深入研究,但是高级别是方法的第一个参数是主题,可以在其余参数输入时进行更改。是不可改变的。在上面链接的方法中,您会注意到第一个参数的类型为ModelMap<Task>
。这是可以变异的Task
个对象的集合。流程看起来像这样(我可能遗漏了一些东西):
"play"
is created in a ModelMap<PlayApplicationSpec>
ModelMap<PlayApplicationSpec>
PlayPlatformAwareComponentSpecInternal
is validated that the number of target platforms is not more than 1 PlayApplicationSpec
ModelMap<PlayApplicationBinarySpec>
based on the PlayApplicationSpecInternal
. The name of the generated binary comes from here somewhere ScalaLanguagePlugin
PlatformScalaCompile
tasks are mutated to use the compile classpath from the PlayApplicationBinarySpec
关于我可以给你的详细信息,而不是真正深入研究ScalaLanguagePlugin
。 ./gradlew model
将为您提供一些报告,说明某些内容的来源并可能会有所帮助,但也可能不会,因为在该模型和普通的Gradle配置模型之间管理的东西都是一样的。