How can I add gradle support to an existing intellij project? - intellij-idea

I have an intellij project that has gradle files in it(build.gradle, settings.gradle, etc.) and I have the project working in intellij. The issue is that intellij can't find any 3rd party libraries so I need to link the gradle project to it. How can I do this to an existing intellij project or at least be able to resolve 3rd party libraries so that the classes don't show up as red in the editor?
I'm on version 2016.1.2 145.972

You can click on the "+" symbol on the Gradle tool window and attach the project. If you don't see the window, use View | Tool Windows | Gradle to bring it up. (Or use the square icon on bottom left). You may then have to click the refresh icon to bring in the dependancies (in case IntelliJ didn't do it).
Refer: https://www.jetbrains.com/help/idea/2016.1/working-with-gradle-projects.html
Alternately, you could just re-import the project freshly using gradle.
Import Existing Project -> Import project from External model -> Gradle

Related

How to link to the existing project in intellij

Eclipse has a good feature that I can link to other project in the same workspace as a dependency specified in pom.xml. Is it possible for me to do the same in intellij ?
Of-course you can do, I am doing a sbt project having dependencies of multiple projects. It will be easy to debug if you attach the dependent projects. It can be achieved easily by holding the ctrl and mouse clicking on any of the methods from the other projects in your current project. It will open the compiled code of the same. Then to the right top corner you can find Choose Sources... . Click that and in the explorer go to your dependency project and select the source. There you can see other project in the same workspace.

Netbeans + Eclipse + Dart -> IntelliJ

At the moment I have 3 IDEs running at the same time, Netbeans for PHP and Python related projects (support for both are poor in Netbeans), Eclipse STS for Java/Spring/Scala projects (STS hangs when the projects get too big) and Dart IDE for Dart projects.
I'm trying out IntelliJ seeing as it has decent support for all the languages I'm working in and somehow it's a lot more stable, much faster, much more intuitive, but I can't figure out how to import multiple projects ... (that's something that just works in both Netbeans and Eclipse)
... there's a Maven Projects tab on the right, if I click the + sign it perfectly imports multiple maven projects for me and lists them in the project box, as soon as I import a non-maven project using file -> import project, all my other projects disappear and I have to re-import those projects via the Maven Projects tab. If I import a non-maven project first and then the maven projects using the Maven Projects tab on the right, I can mix one Dart project and multiple maven projects.
The suggestion out there is to import them as modules under a project, so I create an empty new project called Workspace, I select JDK 1.7 for the project SDK. Under module I click the + sign, find my project, select the pom.xml, add all the pom.xml files for that project and click ok - now I have a project with multiple modules.
Repeat for another project, import all the modules, and first project disappears.
How do I have multiple projects with their own "modules" (modules which are actually standalone projects) in IntelliJ. If projects are the eclipse equivalent of workspaces, is it possible to have multiple workspaces open? If not, how do I switch between them? (if switching is too much hassle, I'll create one mega-project and just add all projects as modules)
You can have multiple projects open in separate IntelliJ windows. Every time you open or create a project, or open a build file such as pom.xml or build.gradle, IntelliJ asks you whether you want to open the project in the same window or a new one.

Can't get Changes tool window (Alt+9) to show on IntelliJ IDEA

I can't get the Changes tool window to show on this project.
The project is imported "from sources" and has no facet and no sdk. Which is ok because I'm only editing it in the IDE and running from the terminal.
I'm on Windows 8.
The tool window does show when I open another java web maven project there.
It also does show for the first (no sdk) project when I'm on Ubuntu.
What might the Changes tool window not like about my project?
The IDE wasn't aware of Git in my project.
That happened because the directory I import this project from isn't the same as the Git repository directory, the former is inside the later.
I fixed it in: VCS > Enable Version Control Integration

How to import and run existing plugins from intellij community edition repo

I'm trying to import and run the IntelliJ git4idea (Git Integration) plugin in order to play around and contribute some of my own code.
I've pulled the Intellij community edition from the github repo, and imported the git4idea plugin as a project. I'm running the Intellij community edition
My main issue is this:
After importing all the modules, the git4idea module comes up as a general module type, and not a plugin module type.
This means that when trying to create a new run\debug configuration, I get [none] under "Use classpath of module", instead of of the ability to select the git4idea plugin. This obviously results in a "Run configuration error: no plugin module specified for configuration".
So the question is -
How can I change the general type of imported "git4idea" to plugin type?
Or better yet, what are the steps required in order to import and build/debug/run a plugin from the Intellij community edition repo?
I was able to solve this by manually reordering file directories, sorting out dependencies and editing the .iml file. The type of plugin is defined by changing type="JAVA_MODULE" to type="PLUGIN_MODULE".
...
This is the answer given by Dmitry Jemerov on the official Jetbrains plugin development forum:
The easiest answer to this is "don't". The IntelliJ IDEA Community
Edition project is set up to be developed as a whole, and the
dependencies are set up accordingly. If you want to hack on the Git
plugin, you simply run IDEA using the provided run configuration, it
runs with all plugins enabled, and you simply make whatever changes
you need and test them using the main run configuration.
If you really want, you can set up a new plugin module and point it to
the source code of the git4idea plugin inside the IntelliJ IDEA
Community Edition Git checkout. This is not too hard, but it's
something you'll need to do from scratch, and you can't use the
existing .iml file.
I had the same no plugin module specified for configuration issue. To work around it, instead of importing, I created a new plugin project and used the existing code directory.
when you import the intelij plugin projects
You should run the 'runIde' task in gradle.
Step-by-step instruction
Build your IDEA plugin (usually done with gradle build).
Start Intellij IDEA.
If you have any project opened, go to menu "File->Close all projects" to return to Intellij IDEA startup screen.
Install the plugin you've just built: on the left side of the "Welcome to Intellij IDEA" startup screen go to "Plugins", then click "gear" icon on the right side, it's located to the right of "Marketplace" and "Installed". From the pop-up menu select "Install Plugin from Disk...", navigate to plugin file (usually in build folder) and click "Ignore and continue" when you see the warning message saying something about signature.
Restart Intellij IDEA.
Open the folder with your IDEA plugin.
Wait until IDEA imported your Gradle project.
Put breakpoints inside your plugin code so you can debug it.
Go to menu "Run->Edit configurations".
In the "Run/Debug Configurations" window on the left side click "+".
Select "Gradle" from the pop-up menu.
On the right side change "Name" to "gradle-run-ide" (without quotes).
On the right side under "Run", inside "Tasks and arguments" field enter runIde ("i" must be capital, other letters small).
Click "OK" to save changes.
Go to menu "Run->Debug 'gradle-run-ide'".
A new, black-colored IDEA window should appear.
In this black-colored IDEA window do whatever you need to do in order to invoke methods of your plugin. When you invoke them, the first IDEA window should stop you on breakpoints you set previously.
Happy debugging.
After changing type="JAVA_MODULE" to type="PLUGIN_MODULE" in *.iml file I was getting following error -
Error running 'IdeaPlugin': Wrong SDK type for plugin module
To fix this go to -
Module Settings -> Platform settings -> SDKs.
Click on Add new SDK
Select Intellij Platform plugin SDK
For home directory select your Inetllij installation dir
Select JAVA SDK you want to use with it.
Once this is added got to Module Settings again
Module Settings -> Project settings -> project.
In Project SDK change the JAVA sdk to the SDK we just added in the above steps.
Run/Debug you plugin now.

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