Visualizing gradle dependencies in Intellij - intellij-idea

Is there a way to visualize project dependencies for a gradle project in Intellij? For a maven project, if you right click in the pom.xml you get a Show dependencies option but there I don't see such an option for a gradle project.
Does this feature exist for gradle project?

I did a small search in IDEA and Google and looks like there is not way to see Gradle dependency but I have found the plugin "Gradle View" which does what you need
http://plugins.jetbrains.com/plugin/7150
You can open a ticket and maybe they will add a better Gradle support in IDEA 15

Related

Intellij IDEA With Multiple Gradle Projects

I am working on two Gradle projects. One of these projects is a supporting library that will be used by other projects in the future so project A depends on project B but not as a 'multi module project'. The dependency is to be resolved through the artifact repo so project a declares it as a compile dependency using it's maven coordinates.
My problem is when working on these two projects in IntelliJ changes to project B aren't made available to project A until I install it (using the Gradle Maven plugin) in my local repo. This is kind of annoying and slows down my workflow. Is there a way to get IntelliJ to automatically update the dependency internally?
This is supported in the latest versions of Gradle and IntelliJ. It is known as a Composite Build.
Composite builds can be declared in the project's settings.gradle file as follows:
includeBuild '../my-app'
or by using the --include-build command line argument:
$ gradle --include-build ../my-utils run
Take a look at the Composite Builds with Gradle and IntelliJ IDEA Webinar for instructions on how to configure the integration.
In IDEA 2017 you can right-click on the gradle module and use Composite Build Configuration to link the current module to one or more gradle module already opened in the current workspace.

Dependency graph in Gradle projects

Is there a way to get the equivalent of Maven Dependency Graph but for Gradle projects in IntelliJ IDEA Ultimate?
They released that feature on 2019.2.
To view Gradle dependencies as a diagram, click on the Show Dependencies icon on the Gradle tool window toolbar or use the shortcut Alt+Shift+Ctrl+U on Linux and Windows / Alt+Shift+Cmd+U on macOS.
https://blog.jetbrains.com/idea/2019/06/intellij-idea-2019-2-eap6-gradle-dependencies-diagram-and-more/
May be very late to answer, but have you checked https://plugins.jetbrains.com/plugin/7150-gradle-view

Gradle dependencies not added as libraries in IntelliJ

I created an intellij Gradle project for some groovy code. Gradle correctly resolved the dependencies and has them added in the Project Structure's modules tab, however they are not loaded in the Libraries tab... Because of this it is impossible to compile the project, it gives me errors on missing libraries. What am I doing wrong?
I'm not an expert on this, having only just discovered a solution to this problem myself, but I found that using the idea Gradle plugin resolved the same issue for me.
So, in build.gradle add:
apply plugin: 'idea'
Then run:
gradle idea
and Gradle will create the .iml files for your project, which Intellij will understand and use to import the libraries. I'd recommend creating a backup of your project first, because if there are other things in your .iml files that Intellij needs, I suspect everything will break! I find them a bit of a mystery, personally.

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

IntelliJ IDEA with multiple gradle subprojects

I'm working on multiple Gradle projects with internal and external dependencies, and so far I am happy that thanks to Gradle's dependency management I can modify a library project without affecting every application that uses the library.
When I need to modify a library project and test it using an application project that uses it, I need to do the following,
Modify the library project and commit to SCM
Trigger CI to build the library project and push it to my Gradle repository
Update the application project's build.properties to refer to the new version of library project
Iterate the above steps until everything works and there is no bug
So it became quite combersome now. Can I configure IntelliJ IDEA so that
All my Gradle projects are in one window, like the screenshot below, which is Twitter's Finagle imported using its pom.xml. Sadly IntelliJ's JetGradle plugin doesn't seem to understand Gradle subprojects.
When build.properties's dependencies are my subprojects, read dependency from local snapshot, otherwise download them from the Gradle repository
Thanks.
If you want to open all projects in a single IDEA window, you'll have to aggregate them into a multi-project build, at least until IDEA 13 hits the market. Before IDEA 13, it's better to use Gradle's IDEA integration. Once you have a multi-project build, all you need to do is to add allprojects { apply plugin: "idea" } to the root build script, run gradle (cleanIdea) idea, then open the generated IDEA project.
Currently in IntelliJ IDEA 2019.2 you can add the gradle subprojects like so
Open Gradle Tool Window via View > Tool Windows > Gradle menu
Click on "Link Gradle Project" button (the plus sign)
Select the build.gradle file corresponding to the subproject
Go to File > Project Structure > Modules > NameOfSubproject
Navigate to main/java and click on Mark as: Sources
Mark the main/resources as Resources
Restart IntelliJ IDEA
The sources of the subproject will be recognized by IntelliJ and you can use Navigate Class action for the classes in the subproject