Gradle Basics (Theory)

Gradle is an open source build automation tool, and is licensed under the ASL. Gradle is  designed for large multi-project builds. Gradle builds upon the concepts of Ant and Maven, and introduced a Groovy-based domain-specific language (DSL) instead of traditional XML form for configurations. We quickly looked into the other popular build tools previously

Gradle supports incremental builds and intelligently determine not to re-execute up-to-date parts of the build tree and dependencies. Though Gradle provides out of the box conventions, it also provides means of developing our own build standards.

Gradle uses a directed acyclic graph ("DAG") to determine the order in which tasks can be run. Maven does this by defining lifecycles and Ant targets are invoked based upon a depends-on partial ordering. Migrating builds from Ant, Ivy or Maven to Gradle can be done easily in stages. Gradle can interface with Maven and Ivy repositories, and can call existing Ant build files. Gradle also provides a converter for turning a Maven pom.xml into a Gradle script.

 

XML vs Groovy Build Files

According to Gradle overview @ gradle.org, they decided to choose a build script based on Groovy dynamic scripting language than XML, to be closer to the Java developers who will be actually using it. However they did not use Java as they required more capabilities than java provides for build activities.

Groovy is an agile and dynamic language for the Java Virtual Machine inspired by languages like Python, Ruby etc. with very less learning curve for Java developers. Groovy uses a Java-like curly-bracket syntax. Most Java code is also syntactically valid Groovy. Though you won’t require any Groovy knowledge for simple build scripts, knowledge of Groovy can be handy for working with bigger and complex build files.

This approach also exposes the raw scripting power of a dynamic language to build scripts to do general purpose programming tasks and control flows. Moreover XML based build files become difficult to maintain and understand when they grow large. 

 

Domain-specific language (DSL)

Since Gradle build files are groovy scripts, you can always use raw groovy scripting. But the preferred approach for gradle is to use the domain specific language (DSL) provided by gradle. A domain-specific language (DSL) is a computer language specialized to a particular application domain, in contrast to a general-purpose language, which is broadly applicable across domains. Gradle’s DSL is easy to learn even without any groovy knowledge. DSL has idioms specific to the build tasks and gradle suggests to use these idioms wherever possible first before actually scripting using raw groovy.  

If something is missing or is not as required, you can also extend DSL through plugins by adding or even modifying tasks. So there is very little need for you to do raw groovy scripting. Also, note that the concept of plugin here is not same as that of maven plugins.

We will see how to use gradle next. You can refer to a more detailed gradle overview @ http://www.gradle.org/overview or any of the references below.

References

http://www.gradle.org

http://www.gradle.org/overview

http://www.gradle.org/downloads

http://en.wikipedia.org/wiki/Gradle

http://groovy.codehaus.org

http://en.wikipedia.org/wiki/Groovy_%28programming_language%29

http://en.wikipedia.org/wiki/Domain-specific_language

Book: Building and Testing with Gradle by Tim Berglund and Matthew McCullough.

Quick Notes Finder Tags

Activities (1) advanced java (1) agile (3) App Servers (6) archived notes (2) Arrays (1) Best Practices (12) Best Practices (Design) (3) Best Practices (Java) (7) Best Practices (Java EE) (1) BigData (3) Chars & Encodings (6) coding problems (2) Collections (15) contests (3) Core Java (All) (55) course plan (2) Database (12) Design patterns (8) dev tools (3) downloads (2) eclipse (9) Essentials (1) examples (14) Exception (1) Exceptions (4) Exercise (1) exercises (6) Getting Started (18) Groovy (2) hadoop (4) hibernate (77) hibernate interview questions (6) History (1) Hot book (5) http monitoring (2) Inheritance (4) intellij (1) java 8 notes (4) Java 9 (1) Java Concepts (7) Java Core (9) java ee exercises (1) java ee interview questions (2) Java Elements (16) Java Environment (1) Java Features (4) java interview points (4) java interview questions (4) javajee initiatives (1) javajee thoughts (3) Java Performance (6) Java Programmer 1 (11) Java Programmer 2 (7) Javascript Frameworks (1) Java SE Professional (1) JPA 1 - Module (6) JPA 1 - Modules (1) JSP (1) Legacy Java (1) linked list (3) maven (1) Multithreading (16) NFR (1) No SQL (1) Object Oriented (9) OCPJP (4) OCPWCD (1) OOAD (3) Operators (4) Overloading (2) Overriding (2) Overviews (1) policies (1) programming (1) Quartz Scheduler (1) Quizzes (17) RabbitMQ (1) references (2) restful web service (3) Searching (1) security (10) Servlets (8) Servlets and JSP (31) Site Usage Guidelines (1) Sorting (1) source code management (1) spring (4) spring boot (3) Spring Examples (1) Spring Features (1) spring jpa (1) Stack (1) Streams & IO (3) Strings (11) SW Developer Tools (2) testing (1) troubleshooting (1) user interface (1) vxml (8) web services (1) Web Technologies (1) Web Technology Books (1) youtube (1)