otc
otc

Reputation: 754

Convert Java Project to Gradle Project in Intellij

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.

Upvotes: 29

Views: 43633

Answers (3)

t.olev
t.olev

Reputation: 143

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

Upvotes: 8

Rich
Rich

Reputation: 975

  • 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.

Upvotes: 2

Orkhan Hasanli
Orkhan Hasanli

Reputation: 786

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.

Upvotes: 48

Related Questions