Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intellij Re-import Gradle Project

I just added a new test source directory to my Gradle project and want IntelliJ to recognize it. I can close the project and reopen the build.gradle file and chose "Delete Existing Project and Import"; is there a way to update the module sources without deleting the existing project?

idea {     module {         // just added these two lines                 testSourceDirs += file('src/integration-test/java')         testSourceDirs += file('src/integration-test/resources')     } } 

I don't want to just manually add the sources, instead I want IntelliJ to re-import the Gradle project structure from the 'build.gradle' file.

Details: Gradle v1.7, IntelliJ v12

like image 900
Mike Rylander Avatar asked Oct 25 '13 18:10

Mike Rylander


People also ask

How do I import an existing Gradle project into IntelliJ?

If you have some custom plugins that require you to import your project from the IntelliJ IDEA model, press Ctrl+Shift+A and search for the Project from Existing Sources action. In the dialog that opens, select a directory containing a Gradle project and click OK. IntelliJ IDEA opens and syncs the project in the IDE.

How do you're import a same project in IntelliJ?

Launch IntelliJ IDEA. If the Welcome screen opens, press Ctrl+Shift+A , type project from existing sources , and click the Import project from existing sources action in the popup. Otherwise, from the main menu, select File | New | Project from Existing Sources.

How do I rebuild a Gradle project in IntelliJ?

From the main menu, select Build | Rebuild Project for the entire project or Build | Rebuild 'module name' for the module rebuild. IntelliJ IDEA displays the build results in the Review compilation and build output.


2 Answers

IntelliJ 13 supports "refreshing" the Gradle project. When the project is refreshed any dependency changes are picked up as well as any changes to the project structure.

In order to do so go to View -> Tool Windows and open the Gradle Tool Window you find the refresh button in the upper bar.

like image 66
Mike Rylander Avatar answered Sep 19 '22 13:09

Mike Rylander


I'm using intellij 2017 and was unable to locate the "refresh" option as described in previous versions of intellij. For me,

./gradlew idea corrected the issue. gradle idea should also work.

UPDATE

As noted in the comments, when using intellij 2017 open the build.gradle file as a project and enable the "auto import" command to avoid this issue all together!

like image 25
P.Brian.Mackey Avatar answered Sep 21 '22 13:09

P.Brian.Mackey