25

I am trying to exclude a particular file in my project from being compiled.

According to the Intellij IDEA documentation you do this by "marking the file as plain text".

However, the context menu in the project view where this functionality is supposedly located has no such action. I am using version 13.02 of Intellij. Here is what my context menu looks like:

enter image description here

Tunaki
  • 132,869
  • 46
  • 340
  • 423
Tyler Durden
  • 11,156
  • 9
  • 64
  • 126

3 Answers3

43

Under File > Settings > Build, Execution, Deployment > Compiler > Excludes, add an entry.

enter image description here

Any attempts to run a path specified here will result in a ClassNotFoundException, and a very important class indicator as well.

enter image description here

Shimmy Weitzhandler
  • 101,809
  • 122
  • 424
  • 632
Makoto
  • 104,088
  • 27
  • 192
  • 230
  • 1
    In newer versions of IntelliJ, it is under `File > Preferences`. Submitted this as an edit, got rejected for some reason. – sam1370 Aug 03 '19 at 19:40
  • @Sam1370: I'm not seeing a "File > Preferences" path with the latest IntelliJ - 2019.2. You may be seeing something OS-specific; what OS are you running? – Makoto Aug 03 '19 at 20:53
  • wait you're right, don't know why I didn't see that in the first place. Maybe I was looking under a different menu and only found preferences there :) That's probably why I got rejected, thanks – sam1370 Aug 04 '19 at 18:22
  • Its in IntelliJ IDEA -> Preferences – happy Feb 25 '20 at 07:09
16

Just to compound on Makoto's answer (would comment but don't have reputation), it looks like this feature does not apply to classes (.java) or assets (images)...for these types of files, it looks like you will need to actually go to the compiler and explicitly state that the file(s) should be excluded.

However, for .htm, .xml, or really anything that isn't a class or asset you will find and can use the 'Mark as plain text' option.

Edit: It looks like you can also go to the 'Messages Make' error / warnings view and Exclude from there, a little less work IMHO. Messages Make shortcut

Justin Horner
  • 321
  • 1
  • 3
  • 7
  • I have a lot of files to exclude and some of them did not generate any error / warnings. How can I exclude those from compile? – JRR Sep 04 '17 at 06:24
  • Also, once excluded how can I add the file back to be compiled? – JRR Sep 04 '17 at 06:34
  • 1
    Settings > Compiler > Excludes. There add the files you want to exclude (and remove the entries to undo the exclusion) – Justin Horner Sep 05 '17 at 20:15
1

The answer that @Makoto has given is pretty much the way to go, but in case that you are like me and you get easily both distracted and frustrated looking for that menu, you could use this shortcut:

press ctrl + shift + a , and in the input box that appears type excludes, and select the first item that appears.

M-Soley
  • 265
  • 1
  • 4
  • 13