Convert Maven Project to Gradle Project

Gradle is a more feature-rich and more modern java build tool, so if you are planning to port from maven to gradle build system, this tutorial may help you.

Maven to Gradle
Maven to Gradle

1. Converting pom.xml to build.gradle

Very first thing – you must have gradle installed on your machine.

Now, go to your maven project’s root directory and execute the command:

$ gradle init

This will generate a bunch of files for you, most importantly a build.gradle which you can now use to run all your builds using gradle commands.

Please note that gradle init automatically detects the pom.xml and creates a gradle build with the java and maven plugins loaded. It means that existing Maven dependencies are automatically converted and added to the gradle build file.

2. Demo

Let’s take an example. I have below-written pom.xml file one of the example projects.

<project xmlns="" xmlns:xsi=""
  <name>AngularSpringMVCExample Maven Webapp</name>

I run the gradle init command into the project’s root directory. I get the following output:

Maven to Gradle Conversion Command Example
Maven to Gradle Conversion Command Example

After executing the above command, the following files are generated in the root folder.


apply plugin: 'java'
apply plugin: 'maven'
group = 'com.howtodoinjava'
version = '0.0.1-SNAPSHOT'
description = "AngularSpringMVCExample Maven Webapp"
sourceCompatibility = 1.7
targetCompatibility = 1.7
repositories {
     maven { url "" }
dependencies {
    compile group: 'org.springframework', name: 'spring-context', version:'4.3.2.RELEASE'
    compile group: 'org.springframework', name: 'spring-webmvc', version:'4.3.2.RELEASE'
    runtime group: 'org.webjars', name: 'angularjs', version:'1.5.7'
    runtime group: 'org.webjars', name: 'bootstrap', version:'3.3.7'
    providedCompile group: 'javax.servlet', name: 'javax.servlet-api', version:'3.1.0'

settings.gradle = 'AngularSpringMVCExample'


A similar file “gradlew” is generated for UNIX environment also.

This file runs the project into a machine where no prior Gradle setup has been done. For example, you download a project from GitHub and want to run that project on your machine.

All you need to do is execute OS specific gradlew file and it will do all things for you.

3. Challenges and Problems

Though the conversion process looks very easy – it is not that much simple. Due to how Gradle and Maven look at how to build a project, there are certain Maven features that may make the process more difficult. For example:

  • Bills of Material (BOMs)
  • “import” and “provided” scopes
  • Optional dependencies
  • Integration tests
  • Custom configurations
  • Less common Maven plugins
  • Custom plugins

Gradle’s official site has instructions on what to do in case you have the above elements in your pom.xml file.

Due to possible conflicts in build process and directory structure, It is advisable to test your new gradle project, thoroughly. Do not forget to check environment properties, unit test case results and integration test results.

Happy Learning !!


Notify of
Most Voted
Newest Oldest
Inline Feedbacks
View all comments

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.

Our Blogs

REST API Tutorial

Dark Mode

Dark Mode