'How can I tell IntelliJ's "Find in Files" to ignore generated files?
I need to do a find in files. I want to ignore or exclude generated files, like JAX-WS artifacts or classes in target folders. How can I tell IDEA to exclude these files from the find?
Solution 1:[1]
I know this is late to the party, and Rob's answer is a decent one. I'd just like to add the following alternative though: if you chose the Custom scope (as in Rob's answer), then leave the selection at Project Files, this will make IntelliJ search a bit more selectively than by default. I don't know what the exact differences are, but of particular interest is that if you mark a directory as Excluded either using the Modules tab in the Project Structure settings, or by right-clicking on a directory and selecting Mark Directory As -> Excluded.
If the files you want to exclude are in a single or relatively few directories so you can easily manually set up these exclusion rules, this is a really nice way of getting the same result without needing to configure a custom scope.
I tested this in IntelliJ Ultimate 14.1.4. I have no idea how it behaves in other versions, but I suspect most of v14 at least will behave the same.
Solution 2:[2]
You can also put the search file filter starting with ! sign to exclude.
Example to search code not in Test Java files:
!*Test.java
If you have a few types of files you can separate with , sign.
Example to search in Kotlin and Groovy files only:
*.kt,*.groovy
This might be also helpful.
Solution 3:[3]
Skip generated files pattern
I use the next pattern to exclude generated files
!file:*intermediates*/&&!file:*generated*/&&!lib:*..*
Solution 4:[4]
I use this filter to create a custom scope to exclude the target folder in play framework applications:
(src:*..*||test:*..*)&&!file:target//*
Also, this is the language reference for the scope definition language: https://www.jetbrains.com/help/idea/scope-language-syntax-reference.html
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Thor84no |
| Solution 2 | alex.b |
| Solution 3 | |
| Solution 4 | nemoo |
