Gradle – Convert Maven Project to Gradle Project

Gradle is 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

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 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 plugin loaded. It means that existing Maven dependencies are automatically converted and added to your gradle build file.

Maven to Gradle Conversion Example

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

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


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

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

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

1) build.gradle

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'

2) settings.gradle = 'AngularSpringMVCExample'

3) gradlew.bat

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

This file is used to run 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 into your machine.

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

Challenges and Problems

Though conversion process looks like 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 what to do in case you have 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 !!

Leave a Reply

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