Partner – Moderne – NPI EA (cat=Spring Boot)
announcement - icon

Refactor Java code safely — and automatically — with OpenRewrite.

Refactoring big codebases by hand is slow, risky, and easy to put off. That’s where OpenRewrite comes in. The open-source framework for large-scale, automated code transformations helps teams modernize safely and consistently.

Each month, the creators and maintainers of OpenRewrite at Moderne run live, hands-on training sessions — one for newcomers and one for experienced users. You’ll see how recipes work, how to apply them across projects, and how to modernize code with confidence.

Join the next session, bring your questions, and learn how to automate the kind of work that usually eats your sprint time.

Course – Black Friday 2026 – NPI EA – main – before_post_content
announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 4th December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

Course – Black Friday 2026 – NPI – main – before_post_content
announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 4th December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

1. Overview

In this tutorial, we’ll learn how to convert a Maven build to a Gradle build. For this purpose, we will use the gradle init command on an existing Maven project.

2. Gradle Setup

Let’s install Gradle on our machine by downloading a Gradle distribution and following the instructions. We can also take a deep dive to learn more about Gradle.

3. Maven Build File

Let’s start with a standard Maven Java project which the following pom.xml file in its root directory:

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.baeldung</groupId>
    <artifactId>maven-to-gradle</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <dependencies>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.12.0</version>
        </dependency>
    </dependencies>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties> </project>

4. Converting to Gradle

Let’s go to the root directory of this Maven project, containing the master pom.xml, and execute the gradle init command. When prompted for a response, let’s type yes and press enter. We should see the following output:

$ ./gradlew init
This will be executed during the initialization phase.

Found a Maven build. Generate a Gradle build from this? (default: yes) [yes, no] yes

Select build script DSL:
  1: Kotlin
  2: Groovy
Enter selection (default: Kotlin) [1..2] 2

Generate build using new APIs and behavior (some features may change in the next minor release)? (default: no) [yes, no] yes

> Task :init
Maven to Gradle conversion is an incubating feature.
For more information, please refer to https://docs.gradle.org/8.2-rc-2/userguide/migrating_from_maven.html in the Gradle documentation.

5. Generated Gradle Build Files

Now let’s recheck the contents of our project’s root directory. We should now see several new files in our root directory. If we want to go deeper, we can look at gradle-build-settings-properties.

5.1. build.gradle

The build.gradle file is the core component of our Gradle build process and is the direct equivalent of the pom.xml file for Maven builds. Here, pom.xml attributes like groupId, version, and dependencies are translated to their Gradle equivalents. Also present is the attribute of sourceCompatibility, which tells us which Java version to use when compiling Java sources. In the plugins section, we have ‘java-library‘, which supports building any type of Java project, and ‘maven-publish’, which supports publishing artifacts to Maven-compatible repositories.

/*
 * This file was generated by the Gradle 'init' task.
* This project uses @Incubating APIs which are subject to change. */ plugins { id 'java-library' id 'maven-publish' } repositories { mavenLocal() maven { url = uri('https://repo.maven.apache.org/maven2/') } } dependencies { api 'org.apache.commons:commons-lang3:3.12.0' } group = 'com.baeldung' version = '0.0.1-SNAPSHOT' description = 'maven-to-gradle' java.sourceCompatibility = JavaVersion.VERSION_1_8 publishing { publications { maven(MavenPublication) { from(components.java) } } }

5.2. settings.gradle

The settings.gradle file is used by Gradle during the initialization phase to identify which projects are included in the build.

/*
 * This file was generated by the Gradle 'init' task.
* This project uses @Incubating APIs which are subject to change. */ rootProject.name = 'maven-to-gradle'

5.3. gradlew and gradlew.bat

Two startup scripts, one for Windows and one for Unix, are also generated by Gradle. These scripts can be used to run the project on a machine that does not have a prior Gradle setup. We can learn more about the Gradle wrapper files by looking at gradle-wrapper.

6. Conclusion

In this article, we learned how a Maven build containing pom.xml can be converted to a Gradle build having multiple build files such as build.gradle, settings.gradle, gradlew, and gradlew.bat.

The code backing this article is available on GitHub. Once you're logged in as a Baeldung Pro Member, start learning and coding on the project.

Partner – Moderne – NPI EA (tag=Refactoring)
announcement - icon

Modern Java teams move fast — but codebases don’t always keep up. Frameworks change, dependencies drift, and tech debt builds until it starts to drag on delivery. OpenRewrite was built to fix that: an open-source refactoring engine that automates repetitive code changes while keeping developer intent intact.

The monthly training series, led by the creators and maintainers of OpenRewrite at Moderne, walks through real-world migrations and modernization patterns. Whether you’re new to recipes or ready to write your own, you’ll learn practical ways to refactor safely and at scale.

If you’ve ever wished refactoring felt as natural — and as fast — as writing code, this is a good place to start.

Course – Black Friday 2026 – NPI EA – main – after_post_content

announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 4th December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

Course – Black Friday 2026 – NPI – main – after_post_content

announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 4th December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW