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 first 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.