Well, you can do it. The important part, of course, that the class with the main function compiles.
There are two ways you can go:
Compile the class that you want to run only (CTRL Shift F9). Run the main function with a right click. It will fail, but IntelliJ will automagically create a temporary running configuration for this main function. Now edit this configuration and uncheck the option to "Make before launch". Then go back to the file and launch the main as before.
Go to the configurations screen, then Defaults and then Application pane. Uncheck the "Make before launch" option and then you're good to go, as in section one, for any main function you'll encounter/create in this project.
Edit
This answer is outdated, and @ipandzic's answer should be used
As this answer suggests (https://stackoverflow.com/a/14793361/986160) you can use Settings > Build,Execution,Deployment > Compilers > Excludes and add the parts of the projects that are unrelated to be excluded from compilation. Make sure that the part you are trying to run doesn't have imports from those excludes.
For whatever reason, none of the above solutions worked for me, on my large legacy Gradle project. However, the error that I had was just because some method in IntelliJ wasn't wired up correctly (i.e. no obvious compilation errors with other areas of the code). As such, I ended up running gradle clean build idea which worked for my purposes. After that, my test class ran without issue.