Gradle dependencies not added as libraries in IntelliJ - intellij-idea

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.

Related

Visualizing gradle dependencies in Intellij

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

Gradle multi-project builds and IDEA, are modules not automated?

I was doing some experimenting with Gradle and created a multi-project build, with multiproject_test dependent on two projects ChildA and ChildB. I put this simple test project on GitHub.
https://github.com/thomasnield/gradle_multiproject_test
Everything seems to be working great on the command line and Eclipse. Everything was compiling and the dependencies were being recognized and used. But when I imported the project into IDEA it did not create the dependencies. It seems like I had to manually create the modules although it did import the source code from the child projects.
My question is do I have to specify these module declarations separately in the build.gradle script for IDEA? Why would it not even compile the dependencies?
UPDATE
Solution proposed below worked great. IDEA handled the build.gradlescript much more gracefully than the idea plugin.
Loading a Gradle project to build an IDEA project by using the idea plugin does not always work well. The recommended way to load a Gradle project in IDEA is to import the build.gradle file from the root project.
More detailed instructions can be found in IDEA documentation here.

Intellij IDEA code completion does not suggest classes coming from maven dependencies

This may sound stupid but here I go (there's no silly question after all, right?): I'm working on a JAVA Maven module with IntelliJ IDEA and the code completion feature works fine suggesting classes from both my module and the JDK.
However, the code completion feature does not seem to be aware of classes coming from Maven dependencies my module depends on.
For instance, my module depends on Maven dependencies such as joda-time.
The code completion popup does not suggest classes such as LocalDate.
Here's my code completion configuration:
What am I missing?
Thanks in advance.
Found the solution:
Clicked on File > Invalide caches/restart
Chose Invalidate and Restart
After restarting IntelliJ rebuild indexes from scratch and code completion works like a charm.
If it is a Gradle or Maven Project As shown in the picture, you may need to import your project build.gradle file if Gradle or maven bom.xml file if Maven. It will sync your project and may download required files from gradle or maven server.
#SenzMate Iot Intelligence

List all gradle dependencies with their licences

I want to list all maven dependencies (including transitive ones) of my gradle build with their licenses. Is this possible with the IntelliJ gradle plugin? If yes, how? Alternatively a gradle command line instruction would be sufficient, too.
I would recommend the license-gradle-plugin. It can report on licenses from your dependencies via the downloadLicense task.
For anybody who ends up here and discovered the license-gradle-plugin appears to be unmaintained, Gradle-License-Report works for this need as well.
The only plugin that has worked for my Android project is Gradle License Plugin
https://github.com/jaredsburrows/gradle-license-plugin
The setup was quite simple - just one line in the project-level build.gradle and another line in the app-level build.gradle. My project is relatively complex, but doesn't have multiple modules btw.
P.S. I've also tried https://github.com/hierynomus/license-gradle-plugin and https://github.com/jk1/Gradle-License-Report with no success.
You can also try the https://github.com/mikepenz/AboutLibraries
It covers the Kotlin Multiplatform as well.
Actually it covers any gradle type projects.

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