在Gradle深层解释中,什么是按照约定建立的? [英] What is build-by-convention in Gradle deep explanation?

查看:193
本文介绍了在Gradle深层解释中,什么是按照约定建立的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Gradle用户指南经常提到Gradle 声明式,并使用按照惯例构建。这意味着什么?



据我所知,这意味着,例如,在 java 插件中,有一些约定,例如
source必须位于 src / main / java 中,测试必须位于 src / main / test 中,资源位于 src / main / resources ,准备在 build / libs 之类的jar文件。但是,Gradle并不强制你使用这些约定,如果你愿意的话,你可以改变它们。



但是第二个概念,我有一个更大的理解问题。像SQL一样,你可以说你想要对你的查询做什么,但是不会说数据库系统如何获取它们,使用哪种算法来提取数据等。

,告诉我更多的正确理解这些概念。

您对 build by convention 的理解是正确的,所以我不必添加任何东西。 (另请参阅Jeff的回答。)



声明式背后的想法是,您不必在任务级别上工作,执行/声明/自己配置所有任务及其依赖关系,但可以在更高级的声明级别上工作。你只是说这是一个Java项目( apply plugin:java),这是我的二进制存储库( repositories {.. ( sourceSets {...} ),这些是我的依赖关系(依赖关系{...} )。基于这些声明性信息,Gradle将确定需要哪些任务,它们的依赖关系以及它们需要如何配置。


The Gradle User Guide often mentions that Gradle is declarative and uses build-by-convention. What does this mean?

From what I understand it means that, for example, in java plugin there are conventions like source must be in src/main/java,tests must be in src/main/test, resources in src/main/resources, ready jars in build/libs and so on. However, Gradle does not oblige you to use these conventions and you can change them if you want.

But with the second concept, I have a bigger problem with understanding. Like SQL you say what you want to do with your queries but do not say how the Database System will get them, which algorithm to use to extract the data etc.

Please, tell me more to understand these concepts properly. Thanks.

解决方案

Your understanding of build by convention is correct, so I don't have to add anything there. (Also see Jeff's answer.)

The idea behind declarative is that you don't have to work on the task level, implementing/declaring/configuring all tasks and their dependencies yourself, but can work on a higher, more declarative level. You just say "this is a Java project" (apply plugin: "java"), "here is my binary repository" (repositories { ... }), "here are my sources" (sourceSets { ... }), "these are my dependencies" (dependencies { ... }). Based on this declarative information, Gradle will then figure out which tasks are required, what their dependencies are, and how they need to be configured.

这篇关于在Gradle深层解释中,什么是按照约定建立的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆