简体   繁体   中英

How to make IntellijIDEA ignore work-in-progress class files?

When I'm working in IntellijIDEA how do I tell it to ignore a class file that may have problems and I want to leave dormant for a while?

It will throw errors when I compile whatever class I am working on until I fix the first "dormant" class.

I have tried adding my class to a bogus package but Intellij doesn't like that either because the path doesn't match.

IntellijIDEA

Settings | Compiler | Excludes , add your WIP files there:

排除

您可以使用Refactor - > Rename File ... ,并更改文件扩展名。

That is set at the inspection level

Configure Current File Analysis CTRL + SHIFT + ALT + H

I have profiles with differing inspection levels setup loosely based on the phase of my project builds ... I'd suggest taking a look at Customizing Inspection Profiles .

在此输入图像描述

To ignore specific files during compilation you can add files individually or recursively in via the project settings panel ...

Configure Compiler Analysis CTRL + ALT + S :: Compiler => Validation

在此输入图像描述

Usually, only the classes that are used in the application are actually compiled.
In your case, I would guess that it's only broken unit tests that hinder the compilation (as opposed to any other Java classes in the /main folder).

The reason is this: When running all unit tests in a package or source folder, IntelliJ searches and includes all the files that appear like unit tests by default: those with Test or Suite in the class name, but also those annotated with @Test or @Suite .

So the easiest way to exclude your test is to create a third source folder, call it /ignore, and not mark it as a source folder in IntelliJ. You can then drop any file you don't want to include in your compilation there temporarily, and drag it back to its original folder when you want to continue working on it. Beware, though: You will get only limited tool support if you open and edit the file within an unmarked source folder, so it should really be used for "parking" only.

You could also change the file extension, as the other answer suggests, but then IntelliJ will also change its handling of the file in other respects, not just during compilation.

Also, if you're using JUnit 4, you can always annotate any single test method, or the entire test class, with @Ignore , and it will be skipped during the test run. This requires the class to be formally correct, though, ie: no compile time errors.

PS: You need to actually move the test to a different folder, if you really want the package to change - not just edit the package declaration. Otherwise, a non-matching declaration will also be considered an error.

A bit late, still

If all your files are in the same package, then right-click on the package in the Project tool window and pick "Mark directory as -> Excluded". All the classes inside the package won't be compiled. You can cancel exclusion any time you want the same way.

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