IntelliJ Idea, run code regardless of errors in unrelated project files

Compiler ErrorsIntellij Idea

Compiler Errors Problem Overview


One thing that I miss from Eclipse is that I can't run code for testing various things (think short main()) if some totally unrelated files in my project contain errors. I've read in FAQ that I can use Eclipse compiler with -proceedOnErrors argument but it still doesn't work. Temporarily fixing unfinished code to compile is not really what I want.

I should note that I use Scala plugin too but still majority of my code are Java files.

Compiler Errors Solutions


Solution 1 - Compiler Errors

Modify your configuration to use Make, no error check option instead of Make.

For more information see this answer

Note that this may not be enough in your use case. Last resort is to use the solution provided by Vics answer.

Solution 2 - Compiler Errors

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:

  1. 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.
  2. 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

Solution 3 - Compiler Errors

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.

Solution 4 - Compiler Errors

  1. Edit the configuration.

enter image description here

  1. With latest versions of IntelliJ, we need to remove the build from 'make before launch' option by clicking '-'. Below is the screenshot.

enter image description here

Solution 5 - Compiler Errors

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionwokyView Question on Stackoverflow
Solution 1 - Compiler ErrorsLovro PandžićView Answer on Stackoverflow
Solution 2 - Compiler ErrorsVicView Answer on Stackoverflow
Solution 3 - Compiler ErrorsMichail MichailidisView Answer on Stackoverflow
Solution 4 - Compiler ErrorsPrateep GedupudiView Answer on Stackoverflow
Solution 5 - Compiler ErrorsentpnerdView Answer on Stackoverflow