IntelliJ IDEA Tips and Tricks

I, like a lot of Java developers, use IntelliJ IDEA as my IDE and I really like it but I find there are a few things that I end up looking up over and over again so I decided to write them all down in one place and then perhaps I’ll remember them or at least I won’t have far to look.

Diamond operator is not supported in -source 1.5

For some reason when you start a new project IntelliJ always defaults to a source version of Java 5 even though at the time of writing Java 11 is out. Perhaps there’s a way to change this default but it takes just a moment to fix. Select File > Project Structure, under the Project Settings select Project and make sure Project Language Level (and the SDK) is set correctly and then under Project Settings again select Modules and make sure the Language Level is set correctly under sources. You might then get an error message “source release X requires target release 1.X”, this can usually be fixed by opening the Maven tab on the right and side and re-importing all modules (that will cause IntelliJ to respect the source and target settings).

Data Source and unable to resolve table “foo”

I seem to always have problems getting IntelliJ to correctly resolve the table names that are present in my database. This leads to the situation where every file that contains SQL is jam packed with errors along the lines of “unable to resolve table foo”. I could live with this except when I commit to Git I let IntelliJ do a scan for errors and these false positives can hide true positives.

The solution is to open the database window which can be found on the right vertical toolbar and set up a data source for the database your using. Open the settings for the data source and then go to the schemas tab. There you should find a list of all the schemas that your connection has access to. Pick the one that is relevant to your project. IntelliJ will read the required information from that schema and correctly highlight the SQL.