Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intellij IDEA and Gradle projects

I have a new project. Should I place apply plugin: 'idea' in build.gradle and run $ gradle idea? Or should I import the gradle project directly into IntelliJ IDEA 14.1? Which one will allow me to add dependencies to build.gradle and have IDEA automatically download & know about them?

like image 547
benwaffle Avatar asked May 04 '15 22:05

benwaffle


People also ask

How do I project a Gradle project in IntelliJ?

Convert a regular project into a Gradle project Open your project in IntelliJ IDEA. In the Project tool window, right-click the name of your project and select New | File. In the dialog that opens enter build. gradle and click OK.

How does IntelliJ recognize Gradle project?

In the Settings/Preferences dialog ( Ctrl+Alt+S ), go to Build, Execution, Deployment | Gradle. On the Gradle settings page, in the Gradle Projects section, select a Gradle project you need. In the Build and run using list, select the appropriate option and click OK to save the changes.

How do I open Gradle project in IntelliJ?

In the Welcome Screen we can select "Open", and navigate to the location with the project code. IntelliJ IDEA will look for known build systems in the project, for example Maven and Gradle, or IntelliJ IDEA config files. The settings.

Does IntelliJ use Maven or Gradle?

IntelliJ build uses IDE's own jps project model and builder for compiling the java-based projects. Including incremental build support. With Gradle build it actually uses Gradle to build the project (think Gradle build task).


2 Answers

From my experience using the idea plugin does not always work correctly in IntelliJ and actually IntelliJ documentation guidelines are to simply import build.gradle file.

Also, Peter Niederwieser who is a Principal Software Engineer at Gradleware answered a similar question ~2 years ago mentioning the following:

If you use Gradle's idea task to generate project files, this is normal, as there is no way to tell IDEA what the class path of the build script itself is. If you instead use IDEA's Gradle integration ("Import from Gradle model"), this problem doesn't exist.

Bottom line, your safer way to go would be importing gradle project directly from IntelliJ.

like image 137
Amnon Shochot Avatar answered Oct 06 '22 10:10

Amnon Shochot


With Intellij 14 you can just open the the build.gradle file using Intellij's File --> Open. this will import the gradle project, including all dependencies. After you change something in the build.gradle file, you can click on "refresh all gradle projects" at the top of the gradle tool window.

You may also mark "use auto-import" under the Build Tools/Gradle tab in Settings. This will resolve all changes made to the gradle project automatically every time you refresh your project.

The idea plugin is the old method of importing a gradle project into Intellij. With the newer versions of Intellij, it has become redundant.

like image 22
Doron Gold Avatar answered Oct 06 '22 11:10

Doron Gold