How to do a Maven to Gradle migration on a Java Spring Boot project

Maven to Gradle migration

Last Updated on November 25, 2022

If you’re planning to migrate your Maven project to Gradle, you’ll be looking for the path of least resistance to get the job done as easily as possible. In this article you’ll discover the 8 recommended steps to migrate your Java Spring Boot project from Maven to Gradle.

Why do a migration to Gradle?

If you’re reading this article you probably know why you want to move to Gradle, but some of the reasons probably include:

  • Gradle’s Groovy syntax is less verbose than Maven’s xml
  • easier to configure thanks to its graph based task hierarchy
  • features incremental builds to avoid rerunning tasks
  • 2-10 times faster than Maven (according to the Grade docs)

If you’re still deciding whether to migrate, check this Maven vs. Gradle comparison for more help.

When running your migration, it’s important to run through a pre-determined list of steps and commit your code after each one. With a Spring Boot project, these steps should end up with having the same (or very similar) built jar file, the application running exactly as before, and with the same tests running.

Starting point: a Maven project

We’ll be using an example Maven project which you can download from this GitHub repository. We’ll go back to the initial commit containing the original Maven project:

git clone
cd maven-to-gradle
git checkout d5fa646871b28a622cca10fb1ca5a52573566fc1

To build and run the Spring Boot application, use the included Maven wrapper script:

./mvnw spring-boot:run

The application includes the following functionality:

  • creates a file at build time containing the git commit hash
  • exposes this information on http://localhost:8080/actuator/info (Spring Boot does this automatically when is provided)
  • has a @SpringBootTest test to check that the application starts up
  • depends on Spring Boot web, data-jpa, actuator, and test libraries

Running the migration

Follow each stage of the migration process using the steps below.

1) Generate a build scan

The Gradle build scan can run against a Maven or Gradle project, and publishes useful build information to for you to access. We’ll use it to get an insight into the Maven build, and later on to compare to the Gradle version.

Add the file .mvn/extensions.xml with the following contents:


Then run mvn install and accept the terms of service when prompted.

Click on the link provided, enter your email address, then click the link in the email in your inbox to see the scan results.

Total build time

Select Performance on the left hand menu, and you’ll see our build took 12 seconds in total:


The Plugins area will be useful to us later to make sure our Gradle build has all the required plugins:

2) Run an automatic conversion

Thankfully Gradle can do a share of the heavy lifting and automatically generate the build.gradle file based on the pom.xml. It will even convert dependencies, but unfortunately not plugins.

Multi-module projects: if you have a multi-module Maven project you can follow the same process, as Gradle will automatically create a build.gradle file for each pom.xml in your project, and link them together correctly.

Install or update Gradle

Make sure you’re on the latest version of Gradle. At the time of writing this was 6.1.1.

gradle --version

Run gradle init

Navigate to the project root and run:

gradle init

Type yes when prompted if you want to generate a Gradle build.

The following Gradle resources have now been created:

  • build.gradle file – the pom.xml file equivalent
  • settings.gradle file – sets your project name
  • gradlew and gradlew.bat wrapper scripts – you should use these whenever you run Gradle tasks to ensure you’re using the correct version of Gradle
  • a gradle directory – this contains the wrapper jar file

Edit your .gitignore file and add the following entries for directories that shouldn’t be added to version control:


3) Build your project and work through any errors

Now we can try to build using Gradle, although we may get errors since the automatic conversion is just a ‘best-effort’ attempt:

./gradlew build

Here’s an example of an error you might see when using certain versions of Gradle.

Gradle can’t find the required repositories. We need to declare mavenCentral() in the list of repositories in build.gradle so that Gradle knows where to look.

repositories {
    maven {
        url = ''

Try ./gradlew build again and you’ll get a success:

4) Compare the built artifacts

Add the following script to It will compare the size of the built artifacts in Maven’s target and Gradle’s build directories.


ls -hl $MAVEN  | awk '{print $9, $5}'
ls -hl $GRADLE  | awk '{print $9, $5}' 

Now run it:


We’re missing 40MB of code here. Could be important? ⚠️

What’s happened is that Gradle isn’t building the full executable ‘fat’ Spring Boot jar since we don’t have the correct plugin. Add the Spring Boot plugins to the plugins section:

    id 'org.springframework.boot' version '2.2.4.RELEASE'
    id 'io.spring.dependency-management' version '1.0.9.RELEASE'

Now build again with ./gradlew build, then run ./ again:

Much better! Of course this verification method is by no means bulletproof, but it gives us a good indication that we’re on the right track.

Complex builds: if you have a complex build, I recommend extracting the two jar files (jar -xvf <jar-file-name>) and comparing the contents using a diff tool.

5) Run a build scan on the Gradle build to see which plugins are missing

Now let’s run a scan on our Gradle build using ./gradlew build --scan and compare with the Maven build scan:


Both Maven and Gradle add a lot of plugins by default. Ignoring all the org.apache.maven.plugins plugins, we can see that we should include:

  • spring-boot-maven-plugin – we already added this one
  • git-commit-id-plugin – we don’t have this one yet, meaning our http://localhost:8080/actuator/info endpoint won’t work. You can see this by running ./gradlew bootRun:
Missing file

6) Convert plugins

At this point we need to convert any remaining plugins to Gradle. Usually there’s a direct equivalent or very similar plugin.

For generating the file we’ll add this plugin to plugins block:

id "com.gorylenko.gradle-git-properties" version "2.4.1"

And add it’s configuration:

gitProperties {
    keys = ['']

Let’s run ./gradlew build and we can see the file has been generated in build/classes:'

7) Ensure tests are running

Run ./gradlew test and you’ll see from the test report in build/reports/tests/test/index.html that our test is not running:

Enable JUnit 5 tests by adding the following test configuration to the end of build.gradle:

test {

Run ./gradlew test again and the test report should now look much better:

8) Manually test the application (if applicable)

If you have a full automated test suite then this step might not be required, but in our case we’re going to manually start the application and verify it has the expected behaviour.

Start the application in Gradle:

./gradlew bootRun

Does http://localhost:8080/actuator/info return us what we expect?

Looks good! ✅ How about http://localhost:8080/vegetables?

Yup, two of your five-a-day. 🍆


Converting your project from Maven to Gradle doesn’t have to be difficult if you follow these steps carefully, ensuring you commit at each stage in case you need to go back to a previous point.

Once your conversion is complete, if you’re working in a team I recommend keeping the Maven build files for a few weeks until your teammates have moved across to Gradle. Don’t forget to also update your CI server.

Then it’s time for the fun part, deleting the pom.xml files and enjoying your more powerful Gradle build.


See the code for this example in this GitHub repository

Checkout out Gradle’s own useful guide to migrations

If you prefer to learn in video format, check out this accompanying video to this post on the Tom Gregory Tech YouTube channel.

Get going with Gradle course
Gradle icon

Want to learn more about Gradle?
Check out the full selection of Gradle tutorials.

How to do a Maven to Gradle migration on a Java Spring Boot project

4 thoughts on “How to do a Maven to Gradle migration on a Java Spring Boot project

  1. Great article 🙂
    For MacOs command from step 4 not working. Correct command is:
    ls -hl build/libs/app.jar | awk ‘{print $9, $5}’
    The output shout same.
    If you wont, you may add comment.

  2. Hi,
    I am unable to build your project – maven-to-gradle-master, as I am unable to pull down the dependency com.fasterxml.jackson.core:jackson-databind:pom:2.6.4
    Found that in my network – it seems that a network restriction is in place.

    So any clues on how I can use another version of the : jackson-databind will be appreciated.
    (say 2.10.4 or equivalent)

    thank you.

    1. Hi Jeevan. jackson-databind is a dependency of Spring Boot, so the version will be related to that of Spring Boot. Try setting jackson-databind as a dependency in your pom.xml e.g.


Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top


Getting started with Gradle just got A LOT easier!

Get Going with Gradle is the fastest way to a working knowledge of Gradle.

✅ Work effectively in basic Gradle projects
✅ Know how to setup Java projects in Gradle
✅ Understand the Gradle fundamentals

And it's yours today for FREE!

Where shall I send your access details?

Please wait...

Thank you, check your e-mail inbox for all the details!