Using Gradle with Maven Part 1: Introduction

One of the features of Gradle that I like the most is its ability to interoperate with other popular build tools such as ANT and MAVEN. We have already seen using Gradle with ANT and here we will see using Gradle with MAVEN. We are not going to discuss the advantages of one over the other, but only how to use both of them together. One of the best things about Maven is that it adds more conventions than in Maven so that you can create build script files with much lesser code than in Maven. See the first java program with Gradle example build.gradle file to see how small it was, and still it did many things on its own. This would have surely required more lines of code in a Maven POM file. If you are not familiar at all with Maven, I would suggest you go through some beginner tutorial for Maven to know the basics of Maven at least.

Gradle offers a bridge to Maven and Ivy artifact repositories in the form of a dependency management definition graph, without demanding remote repositories, thus providing connectivity to open source hosted binaries on sites like Maven Central. You can say Gradle to use the Maven Central repository to resolve its dependencies by adding below in the Gradle build file:

repositories {



This repositories block indicates that the build should resolve its dependencies from the Maven Central repository. Gradle follows many conventions and facilities established by the Maven build tool, including the option of using Maven Central as a source of library dependencies. Gradle also allows the dependency binaries to be stored alongside the source in version control. Gradle users can establish custom dependency scopes if needed. Gradle replaces the strict Maven lifecycle with task defaults set via plug-ins (e.g. java plugin). Common development tasks such as clean, build, test, and JAR the project’s code are included via the simple inclusion of the java plug-in. Even with convenient defaults, Gradle allows to extend the plug-in-supplied task sequence with additional steps if needed.

Maven coordinates (e.g. groupId, artifactId, version etc.) are called as properties in Gradle and most of them they have defaults too. For instance Maven groupId corresponds to Gradle group property with default value as blank and Maven artifactId corresponds to Gradle property name or archivesBaseName, with default value as the project’s directory name. A Gradle build with an explicit version declaration may look as:

apply plugin: 'java'

version = '0.0.1’

You can list out the entire Gradle properties available in command line using the properties flag:

gradle properties

Many of these properties have sensible defaults assigned so that you don’t have to change them in most cases.

We will see dependency management using maven repositories in detail next.



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) ArrayLists (1) Arrays (2) 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) (53) 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 (8) 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 (12) Java Programmer 2 (8) 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) resources (1) 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)