In the previous tutorial, I have explained How to create a Java Gradle in IntelliJ. This tutorial will explain How to import the Java Gradle project in IntelliJ.
Steps to follow:-
Step 1 – Open IntelliJ IDEA and Welcome Screen appears. Click the Open button present on Welcome Screen.
Step 2 – Navigate to your Gradle project and select the top-level folder. Select the project you want to Import. Select the OK button to proceed to the next screen.
Step 3 – A screen appears to Open or Import project. It will have all the possible configurations for the project. As this is a Gradle project, select Gradle project and click the OK Button.
Step 4 – A warning message box will appear. Select Trust Project button and move forward.
Step 5 – The imported project structure in IntelliJ is shown below.
Step 6 – This screen shows that the project is imported and build successfully.
Step 7 – This screen shows the build.gradle of the imported project.
Step 8 – Run the test present in the project. Here, I have run App. Right-click on App ->Run ‘App.main()’. The below screen shows that the project is imported successfully.
That’s it! We are done!!!
Congratulations on making it through this tutorial and hope you found it useful! Happy Learning!! Cheers!!
Step 1 – Open Eclipse IDE. In Eclipse IDE, select File ->Import ->Maven ->Existing Gradle Project. Click NEXT Button.
Step 2 – A welcome screen will appear. You can uncheck the box – Show the welcome page the next time the wizard appears. This is optional. Click the NEXT button.
Step 3 – Browse the location from where you want to import the Gradle project. Click the NEXT button.
Step 4 – This screen allows us to Configure Customized Workspace Settings. This shows that Gradle Version 7.0 is used for this project. Click the Finish Button.
Step 5 – This screen allows us to review the import configuration. If you feel something is incorrect, click the BACK Button.
Step 6 – We can see that the Gradle project Name is Gradle and other details like Version. Click the FINISH Button. This will import the project structure into Workspace.
Step 7 – Below is the imported project Structure in Eclipse.
Step 8 – To check if the project is imported successfully. Run GradleDemo.java class by right click on the Java class and Run As Java Application.
That’s it! We have imported a Gradle Project in Eclipse.
Congratulations on making it through this tutorial and hope you found it useful! Happy Learning!! Cheers!!
Step 1 – Open Command Prompt. Change current folder to the folder where we want to create the Java project.
cd C:\Users\vibha\eclipse-workspace\Projects\Vibha_Personal\Gradle_Project
Step 2 – Create a Project from Gradle Template. Type the below command and press ENTER.
gradle init
Step 3 – Select the type of project to generate. I’m selecting the application option as if I select basic, it won’t create a src directory. Type 2 and press ENTER.
Step 4 – Select implementation language. This is a Java project, so TYPE 3 and press ENTER.
Step 5 – Select Split functionality across multiple subprojects. I have selected 1 as I want only 1 application. Type 1 and press ENTER.
Step 6 – Select build script DSL (Domain Specific Language) – As in Maven POM.xml (XML) is created to build a script file, here we can use Groovy or Kotlin to build the script file. Type 1 (Groovy) and press ENTER.
Step 7 – Select Test Framework – There are 4 different test frameworks. Depending on your requirement, select an option. I have selected 1 (JUnit 4) and press ENTER.
Step 8 – It needs the Project name and Source Package name. If I won’t provide the project name, it will take by default my current folder name which is Gradle_Project. Similarly, if I won’t provide the Source Package name, then it will provide the current project name as Source Package Name.
Project name – GradleDemoFromCMD Source Package – com.example
Press ENTER. init script will run and create a Gradle project. You can see as the build is successfull.
Step 9 – Below is the project structure. As you can see, the name of the project is GradleDemoFromCMD, but that is not the name of the project folder here. But, when I’ll import this folder into Eclipse, the project name will be GradleDemoFromCMD.
Step 10 – Open app folder. There should be src folder and build.gradle. Open build.gradle.
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java application project to get you started.
* For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle
* User Manual available at https://docs.gradle.org/7.0/userguide/building_java_projects.html
*/
plugins {
// Apply the application plugin to add support for building a CLI application in Java.
id 'application'
}
repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
}
dependencies {
// Use JUnit test framework.
testImplementation 'junit:junit:4.13.1'
// This dependency is used by the application.
implementation 'com.google.guava:guava:30.0-jre'
}
application {
// Define the main class for the application.
mainClass = 'com.example.App'
}
This build.gradle contains all the information which I have provided while creating the project.
That’s it! We have created a Gradle Project using Command Line.
Congratulations on making it through this tutorial and hope you found it useful! Happy Learning!! Cheers!!
Step 1 – Open the IntelliJ. It will look as shown below. To create a New Project, click on New Project Icon.
Step 2 – Click on File Option, hover on New Option and click on Project Option as shown below.
Step 3 – Select New Project as Gradle. Project SDK should be current Java version available. Additional Libraries – Java Click on the Next Button.
Step 4 – Below screen will appear. Mention the Name, Group Id, Artifact Id and Version . Click the Finish button
Name : GradleIntelliJDemo Group Id : com.example Artifact Id : GradleIntelliJDemo Version : 1.0-SNAPSHOT
Step 5 – This dialog box will appear on the screen. This provides you the option to open the project in current window or will open a new window with this project. I’m selecting the option – New Window.
Step 6 – This screen shows the structure of Gradle project as well as build.gradle file.
Step 7 – Project Folder Creation – We can see a folder with the name of project – GradleIntelliJDemo in our Eclipse Workspace.
Step 8 – Right click build.gradle and select Run GradleIntelliJDemo. If the build is successful, below screen appears.
This is how we can create the Gradle project – MavenIntelliJDemo in IntelliJ.
Congratulations on making it through this tutorial and hope you found it useful! Happy Learning!! Cheers!!