intellij-ideaintellij-15

In Intellij IDEA 15, how do I exclude certain items from optimize imports?


I typically want IntelliJ IDEA to always optimize imports and never use wildcards. However, in test classes, I never want static imports for the following entries to be optimized, or even removed even if they're not in use:

import static com.jayway.restassured.RestAssured.*;
import static com.jayway.restassured.matcher.RestAssuredMatchers.*;
import static org.hamcrest.Matchers.*;

Is it possible to do this?


Solution

  • You need to specify excluding rules for appropriate Java packages in IntellijIdea Settings.

    Go to File -> Settings -> Editor -> Code Style -> Java. Now you may see: enter image description here

    Then you need to click to tab "Imports". To apply exclusion rules please add packages to "Packages to Use Import with '*'". I added exclusion for org.junit.* and for org.mockito.*: Add packages

    Now you need to save this configuration and even if you go to you test class and run "Optimize imports" it won't do anything with static imports you specified.