Migrate a maven project to Gradle

Asterios Raptis
2 min readFeb 4, 2020

I ‘ve been using maven for many years. It's a great build system but you write your build script in XML and you can not write program logic in XML. A workaround, therefore, maven provides the famous maven-plugins

Comparison Diagram of Maven and Gradle

In return with Gradle, you write your build script in groovy or Kotlin. Kotlin and groovy are modern programming languages and have high order functions and other cool features that you can not do with XML.

Step-by-Step Migration Process

You have to install Gradle as the first step. You can find the detailed installation steps on https://gradle.org/install/. When you have successfully installed you can create a new feature branch with a name like ‘migrate-to-gradle’ from the existing maven project

Go with your preferred command-line program to the main directory from your project where the pom.xml file is and execute the command: gradle init

Code Snippet Comparison
Code Snippet Comparison

This will start the migration progress and the migration guide will ask you the first question to migrate your maven project. Type yes to continue your migration. This will generate all Gradle related files and directories like build.gradle and settings.gradle

You can now check if the migration has successfully finished with executing the command gradle build

This should give the output BUILD SUCCESSFUL

Conceptual Overview of Gradle Benefits

Now, some background information if you come from the maven world the dependencies get downloaded in the directory .gradle/caches/modules-2/files-2.1 this is the equivalent of the maven directory .m2. I have consolidated a guide for some Gradle plugins that I was using with maven https://github.com/lightblueseas/linuxstuff/wiki/Migration-of-maven-projects-to-gradle

So that's it, folks, I hope your migration to Gradle is easy

--

--

Asterios Raptis

Asterios Raptis is a Fullstack Developer and Software Consultant with over three decades of experience in the software development