30

I have a very basic java project.

In Eclipse there is an option to convert a project to a maven project all you have to do is right click on the java project and click "Convert to Maven Project". So basically it creates a pom.xml file for you.

Does IntelliJ have a similar command to convert to Gradle? Searched around but it did not seem like it does.

3
  • The below link should help you.first convert the java project to build using gradle in eclipse then you can import that in Intellij. stackoverflow.com/questions/14615872/… Commented Jul 3, 2017 at 19:28
  • "Add Framework Support" is the menu option Commented Jul 5, 2017 at 10:16
  • How to update IntelliJ to recognize when the repo was converted from Maven to Gradle? Commented Sep 13, 2022 at 18:29

3 Answers 3

49

The simple way to migrate from Maven to Gradle via Intellij IDEA is:

  1. Install Gradle Build Tool from https://gradle.org/
  2. Add Path to System Enviroments (like in Gradle instructions)
  3. Open your Maven project in Intellij IDEA and then open "Terminal" tab.
  4. Write gradle init. Wait until the building process ends and then save & close your project.
  5. Reopen your project and click Auto-import, and wait while Gradle is running. Approximate time - 5 mins.
Sign up to request clarification or add additional context in comments.

5 Comments

I reopened my project as step 5. but no auto-import pop up came up. could you please help me with that?
I think you are missing the point. The OP is not trying to convert from Maven to Gradle, they're trying to convert from an IntelliJ project to Gradle. That's different.
Hi) The same worked for intellij (without maven). Just open Terminal and do other steps. Worked for me
This did nothing useful, it just created a default build.gradle file that doesn't contain any of the settings from my IntelliJ .iml files.
@JesseBarnum it converts pop.xml to gradle not iml to gradle.
8

Convert a regular project into a Gradle project

  1. Open your project in IntelliJ IDEA.
  2. Create a build.gradle file. Add the information you need.

example:

plugins { id 'java' } group 'org.example' version '1.0-SNAPSHOT' repositories { mavenCentral() } dependencies { testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2' } 

As soon as you create a build.gradle file, IntelliJ IDEA recognizes the Gradle build script and displays a notification suggesting to load the project as Gradle. After you load the project, IntelliJ IDEA enables the Gradle tool window.

From: https://www.jetbrains.com/help/idea/gradle.html#convert_project_to_gradle

Comments

3
  • Close your project (you may want to commit first)

  • Select "New Project"

  • Select Gradle (and any other frameworks you need)

  • Enter the directory where the Idea project to be converted is and click "Finish"

Idea should handle the rest, you may need to move your files into main/java (etc)

I don't think there's a simple way to do this in place.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.