DISCLAMER: This isn’t some free advertising for JetBrains, this is only about a developer sharing tips about IntelliJ.
Without a doubt, the most important developer tool is the development environment (called IDE).
My favourite and the one I work with every day at work is IntelliJ (Ultimate version). In this article, I’ll share with you all the tips and tricks I’ve gathered from my experience and from my colleagues. This might help you master this tool and make your work easier.
Don’t leave if you don’t use IntelliJ or even if you hate it! I bet you can apply many of these tricks to your favourite IDE.
Table of Contents
- Convert microservices into modules
- Have effective code reviews
- Revert multiple commits
- Safety checks for Java devs
- Discuss with your database
- Last piece of advice: run dashboard, marked directories, scratch files, install plugins, overuse shortcuts
Convert microservices into modules
If you work on many projects or your project implements a microservice architecture, you have independent projects in many directories.
This means you have to create one IntelliJ project for each project directory. Yet, you can’t have more than one project in a single IntelliJ window.
Creating modules is the solution. The idea is to create one IntelliJ project with independent modules.
You can manage all modules in the Project Structure window (
File > Project Structure). They’re also accessible by right-clicking on a single module and choosi
ng Open Module Settings.
Have effective code reviews
I hope you’re using a version control system such as Git or Subversion. If you aren’t, you should consider learning more about version control systems!
IntelliJ provides a good integration for VCS, especially for code reviews. If your project contains many repositories within your modules, it’s possible to visualize every commit in one place.
First, check if version control knows your directories:
Then, go check this tool window:
You only have to enable the
Show Root Names option to see the modules’ names on the left. The Paths filter allows you to filter using module names. Useful when you work on projects with a microservice architecture!
The right side of this window shows every modified file from the selected commit. You can click on
Show Diff to open a new window and visualize modifications for each file.
If you need to review multiple commits at the same time, select the commits to review (hold the
ctrlkey) and click on
Revert multiple commits
For some reason, you may need to revert a few commits in your project. If you’re not used to doing it, you can get into trouble.
Revert a commit is quite simple: right-click on it and choose revert. Once you eventually fix the conflicts, a commit popup will come up. If you only revert one commit, do as usual without checking the
Amend commit option.
But if you need to revert multiple commits, you have to be a bit more clever. The idea is to create one commit which reverts all commits at once — begin with the most recent to avoid conflicts.
When you revert a commit, you must commit the changes. It means you can’t perform multiple reverts and finally commit the result. My solution is to commit the first revert and then check the Amend commit option to squash the other reverts into this first commit.
Safety checks for Java devs
IntelliJ comes with a lot of features for Java, including Maven integration. It’s highly configurable, but before exploring, you need to check some settings.
- Project SDK (File > Project Structure)
- Java compiler version for each module (File > Settings > Java Compiler)
- Maven configuration (File > Settings > Maven)
For Maven configuration, consider checking
Always update snapshots if you work on microservice architectured projects.
Don’t forget to also check the Ignored Files section to make sure IntelliJ doesn’t ignore your module
pom.xml. If your module is still not recognized as a Maven project, right click on your
Add as Maven Project.
Sometimes you can compile using the terminal, but IntelliJ finds errors because of the Maven dependencies. To fix that, right click on the module
Maven > Reload and then right click again
to Rebuild the module.
Discuss with your database
I tried some clients to deal with databases, but using IntelliJ is far better when you’re also writing code.
You can explore your database without writing any code using the tree explorer. Then, if you double-click on a table, you can also filter results, perform some CRUD operations, and even export the data in many formats such as SQL, CSV and HTML.
As you might think, SQL files support syntax highlighting, autocomplete and the ability to run queries from the file. The good part is that you can write multiple queries in your file but only run highlighted queries with
Ctrl + Enter.
Last pieces of advice
It’s possible to run your applications from IntelliJ, but you need to create a
Run Configuration first. Once some process is running you’ll be able to list them all on a dashboard.
To enable the Run Dashboard, open the Run Configuration popup and select
Defaults. Then, you can add which kind of configuration can appear in your run dashboard.
When you do a right-click on a directory, you have the option to mark it as Source, Test, and even exclude it.
It’s useful, because you can hide excluded files in your project and also filter search results so that they don’t display tests (in scope > Production Files).
Plenty of plugins exist for IntelliJ — almost every popular framework and language has one. You should install those plugins and check if they help you in your daily work.
For instance, check Advanced Java Folding which might be interesting for Java developers. You can also set up a particular font to easily distinguish similar characters such as
l 1 I and
O 0 o. I’d recommend Source Code Pro and Hack which help avoid confusing similar characters.
shift + shiftsearches everywhere for a file
ctrl + shift + Efor recently opened files
ctrl + shift + Fsearches a text in the path (use the module filter)
ctrl + clickjumps to variable/function declaration
ctrl + f12searches variable/function in file
alt + F7lists variable/function usages
Thanks for reading! This was a compilation of tips and tricks I’ve learned with experience and also with help from my colleagues. I hope you found something helpful for your daily work with IntelliJ!
If you found this article useful, please click on the ? button a few times to make others find the article and to show your support! ?
Don’t forget to follow me to get notified of my upcoming articles ?
Check out my Other Articles
- React for beginners series
- Common Mistakes to Avoid While Working with Vue.js