exclude folder and file patterns for java compiler in idea intellij - intellij-idea

I recently migrated from eclipse to intellij. I have many folders and files to be excluded from compilation. Eg. I have about 40-50 folders named 'test' containing class files and folders that needs to be excluded. I also need to exclude any class file whose name ends with *Test.java.
In eclipse the exclusion pattern is - **/test/** and **/*Test.java that I could set at project level.
In Intellij, I cannot find any equivalent thing that works. It is impractical for me to manually add 100s of folders and files individually at - 'Settings -> Build, Execution, Deployment -> Compiler -> Excludes'.
Does Intellij support exclusion pattern for folders and file like eclipse? Can you help me with above example - on what is the pattern and where to set it in intellij?
Please do not ask me to individually add all the test folders and files ending with Test.java to exclude. There are 100s of them. Looking for regex pattern like in eclipse.
Thanks.

Related

How to mark a directory as a generated-test-source root in IntelliJ?

I'm trying out Dagger2 in Intellij 2016.1 (but not with gradle) on ubuntu.
Intellij creates dagger's generated sources in either
./out/production/<ProjectModule>/generated/ or
./out/test/<ProjectModule>/generated_tests/ depending on if it was generated from a source or test directory, respectively.
But from what I tell, I can only mark those directories as either sources root, test sources root, or generated sources root; there is no option for generated test sources root, say.
Why is this important? Because the generated test sources depend on my test sources. If they are marked as a generated sources root then Intellij cannot find the dependencies.
Note: I don't think they should be marked as test sources root because then Intellij tries to compile those again; unless there is some way of preventing this of which I am unaware.
So is there a way to mark this directory as a generated test sources root or something equivalent?
To mark a diectory as "generated test sources root", open the "Project Structure" dialog at Project Settings > Modules and click on the little "P" next to your folder of choice, and select the "For generated resources" button.
Dagger uses annotation processing to generate sources during compilation. IntelliJ has a specific configuration for this feature in Settings -> Build, Execution, Deployment -> Compiler -> Annotation Processors
When it is enabled IntelliJ automatically adds generated sources to project.
With annotation processing enabled I can see that generated test sources are marked both as Test Sources Root and Generated Sources Root. But when I try to manually set both flags it does not work - I get flags Sources Root and Generated Sources Root.
For me it looks like a bug.
Here's what worked for me. Create a directory in the Module root called generated and under it have two simlinks to <ProjectRoot>/out/production/<ProjectModule>/generated/ and <ProjectRoot>/out/test/<ProjectModule>/generated_tests/. Mark the first as Resource Root and the second as Test Resource Root.
I created the new directory and simlinks because it appears Intillij auto-marks <ProjectRoot>/out as Excluded.
I marked the directory as Test Resource Root so that Intellij doesn't try to compile the source twice to the same class. (Hint: big complains from the compiler.)
In the end, no red squiggles and auto-complete works.
Note: I didn't change the Intellij's generated sources directory for the module. (Well, I did to try another answer, but changed it back.)

TeamCity IntelliJ Inspections - Include Files in Inspection Scope

Question: How can I get TeamCity to run inspections against the 3 html files in the www root directory?
I'm working on a node.js project. The team are all using JetBrains IDEA based IDEs. We have shared our Inspection Profile and a Scope for them to run against.
We have just setup TeamCity and have a build configuration to run the Inspections. It is working identically for everything except the 3 html files directly under the "www" directory. The problem is that errors for those 3 files are reported in IntelliJ but not in TeamCity.
The only thing that appears to be different is the scope. IntelliJ uses scope defined in an xml file. TeamCity scope is set through the UI (build step form field "Include / exclude patterns"). TeamCity's scope syntax is different to IntelliJ's ...for the life of me I cannot get TeamCity to operate on the same scope!
Intended Scope
Here is a picture of the Project with the inspection scope underlined in green. We want to exclude libraries and the very root folder of config, but include everything else (i.e. everything we write).
TeamCity Scope
I have tried 2 strategies and both seem to work in IntelliJ and fail on TeamCity.
Attempt 1 - Include Only:
+:backend/**
+:tests/**
+:www/css/**
+:www/dist/**
+:www/images/**
+:www/*
Attempt 2 - Include entire www then Exclude:
+:backend/**
+:tests/**
+:www/**
-:www/components/**
-:www/components-unmanaged/**
-:www/data/**
-:www/images/**
IntelliJ Scope
In IntelliJ both work.
Attempt 1 - Include Only:
pattern="file:backend//*||file:tests//*||file:www/css//*||file:www/dist//*||file:www/images//*||file:www/index.html||file:www/loadsave.html||file:www/logical.html"
...more readable with some line breaks:
file:backend//*
||file:tests//*
||file:www/css//*
||file:www/dist//*
||file:www/images//*
||file:www/index.html
||file:www/loadsave.html
||file:www/logical.html
Attempt 2 - Include entire www then Exclude:
(file:backend//*||file:tests//*||file:www//*)&&!file:www/components//*&&!file:www/components-unmanaged//*&&!file:www/data//*&&!file:www/images//
...again, more readable with line breaks:
(
file:backend//*
||file:tests//*
||file:www//*
)
&&!file:www/components//*
&&!file:www/components-unmanaged//*
&&!file:www/data//*
&&!file:www/images//
References
https://confluence.jetbrains.com/display/TCD9/Inspections#Inspections-IdeaPatterns
the pattern must satisfy the following rules: must end with either **
or * (this effectively limits the patterns to only the directories
level, they do not support file-level patterns);
...
the include pattern has a special behavior (due to underlying
limitations): it includes the directory specified and all the files
residing directly in the directories above the one specified.
Other Thoughts: Differing Inspection Support
The only other thought I had was that perhaps TeamCity just plain doesn't support the HTML inspections category that IntelliJ does, or so some bizarre reason it refuses to assess .html files.
Software Versions
IntelliJ IDEA 2016.1.2 (Build #IU-145.972, built on May 14, 2016)
TeamCity Professional 9.1.7 (build 37573)

xml files are not copied to target intellij idea

I have some xml files within the source folder along with the java files.
Intellij Idea is not copying them to the target folder.
I want those xml files to be along with the classes in the target.
Eclipse does this fine.
Can anyone please tell how to achieve this in Intellij Idea?
If, like me, the other answer didn't solve your problem -
If IDEA thinks your project is a Maven module (or once was), and it isn't, it'll behave like this. You can fix this by closing the project, editing the .iml file to remove the isMavenModule property, reopening, and rebuilding:
<moduleorg.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true"type="JAVA_MODULE" version="4">
In its default configuration, IDEA should copy any xml file that are in a source directory into the target directory. Other build tools may not. So this answer is assuming you are making the project via IDEA's internal build/make. If using maven (or gradle), you should place your resources in src/main/resources and not src/main/java as Engineer Dollery mentions in his/her comment.
If you are using the IDEA builds and it is still not copying them over, there is a setting you can check. Go into Settings > Build, Execution, Development > Compiler. On the Compiler settings dialog at the top is a "Resource Patterns" text field. This will define what files IDEA will and will not copy over. The default entry is:
!?*.java
!?*.form
!?*.class
!?*.groovy
!?*.scala
!?*.flex
!?*.kt
!?*.clj
!?*.aj
It is just a set of negation patterns of things not to copy over. So XML files should be copied. Check this setting and see if there is something in it to prevent xml files from being copied.

Configure automatic excluded directories and other directory types when they are present

In the Community Edition when I import a module IntelliJ goes through and tries to figure out which directories are what types. The modules I deal with sometimes have a src and a test directory, which work fine, but more often than not the test directory is actually named tst. IntelliJ likes to mark is as a "Sources" directory rather than "Tests". With the tools I am working with, the dependency configuration and generation of the .iml file happens after this, as well as using a modified build system that is not IntelliJ supported. I have to build via commandline which generates a build folder which I would like to have automatically excluded.
So a couple questions.
Can I configure IntelliJ to automatically recognize different folder names "Tests" and mark them as such?
Can I configure IntelliJ to automatically mark a folder as excluded when it is present in a module?
You can't configure it, the list is hard-coded. However, I've added "tst" to the list of names that are recognized as test source roots; that fix will be included in IntelliJ IDEA 14.1.
You can add "build" to Settings | File Types | Files and folders to ignore. Then IntelliJ will ignore the directories and files named "build" anywhere in your project structure. Given that "build" is a fairly common name, this may or may not be what you want.

"Duplicate class found" - IntelliJ and .class files

I recently imported one of our company's project into IntelliJ Idea (10.5.1). We build and run the project using an ant build script and IntelliJ supports that just fine.
However, IntelliJ seems to have a distinct problem when the compile output directory equals the source code directory, ie .class files are placed in the same directories as their corresponding .java sources.
(Note that I am aware that is not a proper way to go, but tell my boss that. This project is over 15 years old and correspondingly large, too many things depend on it to be this way, there is nothing I can do about that.)
So once things are compiled, IntelliJ detects the .class files and adds them to the project tree. The problem here is that it considers them class declarations, thus I get a "duplicate class found" message for each and every class. This doesn't make me unable to work, but it is extremely annoying as you may guess.
I tried making the IDE ignore .class files, but apparently that makes it not load any classes at all, including the JRE runtime and anything else located inside of .jar files.
Is there any way to make IntelliJ Idea ignore .class files which are in the same location as their .java sources?
Make sure that you've configured the output directory to the source directory, disable the Exclude of the output directory to see your files.
I coped with this same problem when cloning a project from Bitbucket. To solve it in IntelliJ:
Project Structure > Modules > Source > Source folder > <<"Eliminate the unwanted source folder">>
In my case, I had non-implemented classes in one source folder and a second source folder with the implemented classes (same class names).
I deleted one, built again, and the problem got solved.
Give it a try!