Nice keyboard shortcuts
- Select In: Alt+Shift+1. To quickly select the current element in any view (Project view, Maven view, etc.)
- Quick Documentation: Ctrl+Q. To view documentation for whatever object (class, type, etc.) currently at the caret.
Working with version control systems
Useful process for larger projects:
- Open the Version Control window using View > Tool Windows > Version Control.
- Click Local Changes to show local changes (which will include conflicts)
- Click the gear icon and Group By either Directory or Module (makes it easier to just work on merge conflicts in a specific directory or module)
Debugging unit tests using IntelliJ
- Create a new Run Configuration in IntelliJ.
- Set the command line property to your test Maven goal name, e.g.
- On the Runner tab, set VM Options to:
- Set any breakpoints in your code
- Now Debug your Run Configuration, e.g. Ctrl+D, or Run → Debug ‘my-app [test]’.
Debugging an external application
- Choose Run → Edit Configurations.
- Add a new Configuration of type Remote. Name it debugging.
- Copy the command line arguments for running remote JVM (e.g.
- (Optional) Modify
suspend=yto make the Java application wait until the debugger is connected before starting.
- (Optional) Set the debug flags in the environment variable
- In a Terminal, start the application to be debugged.
- In IntelliJ, start the remote debugger (Run → Debug → debugging).
java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005 -jar target/spring-boot-camel-xa-1.0-SNAPSHOT.jar
Debugging for specific tools/frameworks
Thorntail Maven Plugin
Set the property
thorntail.debug.port which causes Thorntail Maven Plugin to suspend on start and open a debugger on this port (when using
start goals), e.g.:
$ mvn thorntail:run -Dthorntail.debug.port=8000
IntelliJ tries to build the entire project before running a single test:
- Run → Edit Configurations
- Navigate to JUnit → Your project, and then remove Make from the list of ‘before launch’ tasks.
Cannot resolve classes/objects/dependencies (lots of squiggly red underlines everywhere):
- Check that the project has been added as a Maven project (right-click the pom.xml → Add as Maven Project)
- Ensure that IntelliJ is using the correct Maven binary - go to Settings → Maven, and check the path to the Maven installation location, and
- Check that artifacts can be resolved correctly. Drop to a Terminal and, using the same Maven binary configured in IntelliJ, try
mvn -U help:effective-pom. If artifacts can’t be resolved here, then fix this first.
- If you’re pulling artifacts from a Nexus repository, check that it’s able to pull artifacts from the web. Log in to Nexus and check the status of your proxy repositories.
- Check that
maven-compiler-pluginis configured correctly (e.g. with a version number)
Package names aren’t resolving (classes can’t see other classes, etc.):
- Check that the
testfolders have been added as Sources
- Right-click the
src/main/javafolder, right-click → Mark Directory as → Sources Root
- Right-click the
src/test/javafolder, right-click → Mark Directory as → Test Sources Root