Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is build-by-convention in Gradle deep explanation?

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.

like image 834
Xelian Avatar asked Jan 17 '14 15:01

Xelian


People also ask

What does Gradle build do?

Gradle is a build automation tool known for its flexibility to build software. A build automation tool is used to automate the creation of applications. The building process includes compiling, linking, and packaging the code. The process becomes more consistent with the help of build automation tools.

What is afterEvaluate in Gradle?

> gradle -q test Adding test task to project ':project-a' Running tests for project ':project-a' This example uses method Project. afterEvaluate() to add a closure which is executed after the project is evaluated. It is also possible to receive notifications when any project is evaluated.

Which programming language should you know to configure a project in Gradle?

Gradle's build script are written in Groovy programming language. The whole design of Gradle is oriented towards being used as a language and not as a rigid framework. Groovy allows you to write your own script with some abstractions.

How Gradle works internally?

During Initialization, Gradle decides which projects are to participate in the build. During Configuration, task objects are assembled into an internal object model, usually called the DAG (for directed acyclic graph). During Execution, build tasks are executed in the order required by their dependency relationships.


1 Answers

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.

like image 106
Peter Niederwieser Avatar answered Oct 10 '22 01:10

Peter Niederwieser