45

How do I enable partial compiles in IntelliJ?

The same feature in NetBeans where by one can run a main method in a class without having non-dependecies in the same project be required to also compile.

EDIT:

After performing what CrazyCoder suggested, with some success, now I get ClassNotFoundException when trying to run a file not associated with those that were not compiling. After fixing the non-compiling files, it runs just fine.

I actually made in error in the same non-compiling file to test and it still works.

Could it be a bug?

EDIT:

Followed instructions still not working.

enter image description here

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
BAR
  • 15,909
  • 27
  • 97
  • 185
  • I've updated the answer with the tip about Eclipse compiler and `Proceed on errors` option. Yet another solution would be to exclude broken code from compilation. – CrazyCoder May 29 '13 at 18:12
  • 2
    It should just work! This is a 'professional' IDE if netbeans just does it so should yours. – BAR May 29 '13 at 23:45

7 Answers7

92

IntelliJ IDEA doesn't welcome working on the project that fails to compile, but there are several options:

  • use Compile action from the file/folder context menu, disable Build in Run/Debug configuration.
  • in the Before launch section of the Run/Debug configuration remove Build and add Build, no error check instead. Now start the configuration and it will ignore compilation errors trying to run on whatever classes managed to compile. enter image description here

You should note that Make will fail on the first error and will not try to proceed further. In this case you should use explicit Compile action. Make also deletes output class files for the sources with errors.

If you want compilation to proceed after errors, you should switch to Eclipse compiler in IntelliJ IDEA Settings | Compiler | Java Compiler. When Eclipse compiler is selected, Proceed on errors option appears and it's enabled by default. With Eclipse compiler, an option to Proceed on errors enabled and Build, no error check in Before launch section you should get the desired behavior.

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
  • 3
    Where is the run/debug config? – BAR May 28 '13 at 06:45
  • I ask because the obvious config I find has no obvious way of doing what you proposed. – BAR May 28 '13 at 06:53
  • 3
    Check [this screenshot](http://img801.imageshack.us/img801/7714/20130528105621.png) and [refer to the documentation](http://www.jetbrains.com/idea/webhelp/creating-and-editing-run-debug-configurations.html). – CrazyCoder May 28 '13 at 06:57
  • I have to create a config for each class file I wish to run?? This is not obvious.. even with help. It should be *MUCH* easier. Please break it down step by step, already tried the docs you provided. – BAR May 28 '13 at 16:05
  • 2
    Edit the default configuration, remove the Make step, add Make, no error check step. Now right click on a class and Run, the new temp configuration will be created automatically and it will inherit default settings. It's really simple, I can't explain it better. – CrazyCoder May 28 '13 at 16:07
  • That is an order of magnitude more helpful, thank you. I kept editing configs for the classes themselves instead of the default. – BAR May 28 '13 at 16:13
  • Setting the compiler to Eclipse, SDK to 1.7 and support down from 8.0 to 7.0 and make no error seems to work. Please focus on making this work by default for future release as I am sure most devs do not write perfect code every time. Thanks for the help. – BAR May 29 '13 at 23:57
  • One more thing, it keeps jumping to files that have errors for fixing even though again they are not needed. Is there an option? – BAR May 30 '13 at 20:53
  • 2
    Yes, [there is an option](http://img10.imageshack.us/img10/5531/20130531012348.png). – CrazyCoder May 30 '13 at 21:24
  • FYI, this solution is also referenced here : [IntelliJ IDEA Q&A for Eclipse Users](https://www.jetbrains.com/idea/documentation/migration_faq.html), search : _Q: What happened to incremental compilation? How do I compile my project?_ – Guillaume Husta May 22 '15 at 13:39
7

Navigate to the Build menu at the bottom of your test editor, right-click on the folder that contains error messages that you find irrelevant.

Choose "Exclude from compile".

Screenshot

tomerpacific
  • 4,704
  • 13
  • 34
  • 52
Nelson Ke
  • 73
  • 1
  • 2
5

To make CrazyCoder comment more visible, if you go for the "proceed on errors" behavior you may want to uncheck

Settings | Compiler | Automatically show first error in editor.

Arnaud P
  • 12,022
  • 7
  • 56
  • 67
4

I'm working with 2020.2.3 version of IntelliJ.

I've tried all CrazyCoder's suggestions, but nothing works for me.

Eclipse Compiler + Build No-Error-Check

IntelliJ just refuses to Run anything (unit tests, main() methods...) because errors exist in the project. All I can say is that Eclipse is still working where IntelliJ remains blocked.

Lovegiver
  • 413
  • 6
  • 22
4

Step 1: Setting as follow:

enter image description here

Step2: Build Project Automatically

enter image description here

Step 3: Modify Run configuration

enter image description here Step 4: close all app console-view tabs in Run View, then run app again Ctrl+Shift+F10

HungNM2
  • 3,101
  • 1
  • 30
  • 21
2

Recompile only selected files:

  1. Select packages or files that needs to be compiled.
  2. Menu → Build → Recompile selected files (⇧ ⌘ F9)

If you need to run or debug, you need to set Do not build before run:

  1. Menu → Run → Edit Configurations...
  2. ☑︎ Your target run configuration
  3. Run / Modify options → Java / ☑︎ Do not build before run
jqgsninimo
  • 6,562
  • 1
  • 36
  • 30
0

Another way of doing this is to set

Use classpath for module field

in Junit configuration tab in your test configurations as your own module. By default it is all_local_extensions.

Attached screenshots.
Before - When classpath is all_local_extensions After- When classpath is indcore

Farrukh Chishti
  • 7,652
  • 10
  • 36
  • 60