ChrLipp
ChrLipp

Reputation: 15678

How to use an existing Gradle project in IntelliJ IDEA 13/14

I am using Gradle and IntelliJ IDEA. Normally I use apply plugin: 'idea' to generate the IDEA project files. With IDEA 12 I was used to work with the JetGradle tool view.

Now I updated to IDEA 13 and the JetGradle tool view is gone. When I use the old run configuration gradle:run, IDEA tells me:

Error running gradle:run:
Module 'X' is not backed by gradle.

How can I activate the gradle build in IDEA 13 without the tool view? I found this tweet from Cédric Champeau, but was still not able to solve it. Do I have to turn my simple gradle project into a multi module project or what?

Update
With File - Import Project ... I can import the build.gradle file and than I can choose View - Tool Windows - Gradle, which was hidden before. Is this the way to go?

Upvotes: 14

Views: 25297

Answers (5)

senseiwu
senseiwu

Reputation: 5279

you can go to Project Structure (Ctrl + Alt + Shift +S) and then under the Modules, click "Import Module" and choose your build.gradle from the project file repo. It will make the module gradle aware and then you will also see the Gradle window

Upvotes: 1

user1712628
user1712628

Reputation:

I have found that when you initially import a gradle project into Idea, if you don't have all of your directories created yet, the gradle tool window vanishes while you are importing into Idea. (It is there when the import starts, but at the end it disappears.) However, if I manually build the project first (on a mac, >gradle clean build), and then go back to IDEA and import the project, the gradle tool window stays active. Hopefully this will help someone else.

Upvotes: 1

user3231931
user3231931

Reputation: 331

The simplest way to do this is to use the Import Project option if you cannot use the gradlew idea to produce the idea project

Upvotes: 0

ChrLipp
ChrLipp

Reputation: 15678

Tested with Gradle 1.9. In my opinion there are 2 issues:

  • Issue 1: when using gradlew idea I expect to receive a valid IDEA project without the need to import it. There are discussions on the gradle forum, see this Gradle forum post. In this Jetbrains forum post it is told that there is no backward compatibility with IntelliJ 12 gradle projects at the moment.

  • Issue 2: With IDEA 12 it was possible to open the JetGradle View even if the current project was not a gradle projcet. But the view displayed the message "There is no linked Gradle project. You can Add one" and offered you the possibility to convert the project to an gradle project with a simple click. In IDEA 13 it is not possible to open the Gradle View when the current project is not a gradle project. I asked a question here.

In the Gradle forum post mentioned above Peter Niederweiser stated:

The preferred way of integrating with IDEA 13 is to use IDEA's Gradle import, without running gradle idea. (You should still apply the idea plugin though, and it's still important to apply it to allprojects {} rather than subprojects {} when dealing with multi-project builds.)

So the answer from Mark Vedder is correct, altough I would have liked to have more information.

Upvotes: 7

Javaru
Javaru

Reputation: 32026

What you state in your update is the correct way to go. The Gradle Plug-in received a lot of love in the IDEA 13 update and has changed a bit. An import of the Gradle build file is necessary. And as you have noted, the JetGradle tool window is now named simple Gradle

Upvotes: 9

Related Questions