简体   繁体   中英

Enable Partial Compilation in IntelliJ IDEA

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.

在此处输入图像描述

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. 在此处输入图片说明

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.

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 .

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".

截屏

Here is how to globally enable partial compilation in Intellij Idea:

Go to File > Settings > Build, Execution, Deployment > Compiler > Java Compiler and check "Generate no warnings" checkbox. 如何全局启用部分编译

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

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.
之前 - 当类路径为 all_local_extensions 时 After- 当类路径为 indcore 时

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.

Step 1: Setting as follow:<\/strong>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM