Appendix A. Integrating Maven – Gradle

Gradle is gradually becoming an important and stable tool for project automation (at the time of writing this book, the latest version used is 2.0). We decided to mention this tool because its percentage of adoption is growing fast; moreover, it was adopted as an official building tool for Android apps by Google at Google I/O 2013. After an official announcement of the Gradle adoption by Google, this tool was completely integrated into the developer IDE Google Android Studio; the new Eclipse plugin will be introduced by the end of 2014, as announced by Gradleware (the Gradle developing team). All these facts, together with Gradle's ability to download dependencies from Maven repositories, have made Gradle eligible to be mentioned in this book.

What is Gradle?

Gradle is a project automation tool that was brought up on the concepts of Apache Ant and Apache Maven. Among Apache's tools, Gradle does not use an XML tag language in order to define the project structure and operation/task to execute; it introduces a Groovy-based domain-specific language (DSL).

Ant and Maven (more often Maven) define a lifecycle that invokes different tasks in a specific order, and every defined task is associated with a specific phase of the lifecycle. Despite Maven's and Ant's behavior, Gradle uses directed acyclic graph (DAG) to determine the order in which tasks can be run; using this structure, Gradle can determine which task has to be executed before or after, without a standard order of execution.

A match point between Gradle and Apache Maven is the capability to manage multiproject builds. Gradle can support incremental builds by determining which parts of a subproject are up to date, so a task that depends on these parts does not have to be re-executed.

The most interesting Gradle feature is represented by the ability to use Maven repositories for dependency management (Ivy repositories can be used too). It is possible to use remote and local repositories and declare nonstandard Maven repositories as custom repositories.

Like Maven, Gradle makes use of a plugin that provides additionally functionalities to accomplish common tasks to build and assemble projects in packages such as JAR, WAR, and EAR used by the Java programming language. The Android plugin compiles and assembles an app with all the tools to publish and sign the generated APK.

Actually, Gradle can build different programming languages:

  • Java: This adds Java compilation, testing, and bundling capabilities to a project. It serves as the basis for many of the other Gradle plugins.
  • Groovy: This adds compilation, testing, and generation of documentation.
  • Scala: This adds compilation, testing, and generation of documentation
  • ANTLR: This generates source files for production and testing.

There are many other incubating plugins for other languages, such as:

  • assembler
  • c
  • cpp
  • objective-C
  • objective-cpp
  • windows-resources: Adds support for Windows resources in native binaries

Other kinds of plugins are represented by integration plugins. They are:

  • application: Adds tasks to run and build Java projects at the command line
  • jetty: Deploys your web application to a Jetty web container embedded in the build
  • ear
  • war
  • osgi
  • maven: Adds support to deploy artifacts on Maven repositories

These plugins are only a few representative numbers to help explain what Gradle is. More documentation can be found online in order to get a deeper understanding of the Gradle mechanics.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset