IntelliJ and Perforce Integration: Client Spec issue when using Project structure outside of client spec root - intellij-idea

I want to use IntelliJ in the following manner. A Project (akin to Eclipse workspace) that contains multiple modules (akin to Eclipse Projects). As you can guess I am moving over to IntelliJ from a more recent Eclipse background.
I set up an empty project called MainProject which appears in the dir structure:
C:\IntelliJProjects\MainProject
This correctly contains my ".idea" directory. I want this to stay out of source control and on the C drive.
I then added two Java modules, one for each component within the project that I will work on. These are in perforce and under a p4 client spec with a root
V:\dev
("V" is a network drive that the code has to live on but I do not want the IntelliJ project files to live there). The two modules have a content root
v:\dev\component1\trunk\src
v:\dev\component2\trunk\src
This all works ok. I have marked the content correctly in the module, src, test etc
Now for the issue. When I try to set up perforce the project root is:
C:\IntelliJProjects\MainProject
but the client spec root is
v:\dev
so I get the following error when I test the connection
<pre>
Connection problems: </br>
Wrong client specification: </br>
Client roots: </br>
v:\dev </br>
Actual root: </br>
C:\IntelliJProjects\MainProject </br>
</pre>
When using Eclipse, Perforce has never been concerned with where the Eclipse workspace is so likewise I was not expecting IntelliJ to be concerned with where the project file is stored. I can see many cases where you would not want the project or indeed the module .iml files under perforce but the code certainly would be.
The only way around this would be to have the project file on the network drive under the client spec but as it is at the project level it could not rightly live under either:
v:\dev\component1
v:\dev\component2
so I would have a project under
v:\dev
which would break if I ever altered client specs
The only other way I have figured out is that I add
v:\dev
as a directory under "Version Control" where you can add in directories
has no VCS
v:\dev has VCS defined as perforce
Is this the only way or can anyone advise a better approach?

I know this is an old question, but i'm having the same problem now and i managed to solve it.
I have an IntelliJ project in a folder A, while my Perforce workspace is in folder B.
In my project i have both modules inside the project folder and inside the Perforce workspace, and i was having the "Wrong client specification" error as i mapped the whole project to Perforce.
All i had to do was to go to:
IntelliJ project preferences -> Version Control
click on the + and add map my entire Perforce workspace directory to Perforce as a VCS, as in the picture:

Your setting is correct. If you map whole "Project" to Perforce VCS, IDEA will consider everything in your project (including .idea) to be under Perforce, which is not what you want.
BTW it's strongly advised to keep project source on local disks, otherwise IDEA might have issues with file synchronization or just might function slower than it could be.

Related

IntelliJ: display folder structure like NetBeans

I prefer IntelliJ over NetBeans for Maven Java development, but I'm wondering how to get the displayed project structure that NetBeans has into my IntelliJ project. Please see the image below.
Edit: some more information about what I want.
IntelliJ displays the actual folder layout: the folder webapp is under root/main/webapp. However, NetBeans recognizes that this is an important folder and pulls it up to project level, so virtually root/webapp. This is just a visual thing: in reality the folders remain the same.
In this example, the folder is only 1 tier lower in IntelliJ than in NetBeans. But sometimes, the webapp folder is in root/./././webapp (example). Having to open 5 folders before finally ariving at the webapp folder is annoying and by pulling it up it is clearer and it saves time.
Go to settings(as shows in image) of Project Structure.
Then select Flatten Packages and Hide Entry Middle Packages. You will get structure like Netbeans in the IntelliJ
For more details please visit: https://www.jetbrains.com/help/idea/2017.1/project-tool-window.html

IntelliJ IDEA directory-based format and .iml file(s)

We started a directory-based project in IntelliJ IDEA (currently using version 2016.3 build 163.7743.44). Everything is fine, the .iml file is inside .idea/modules and we can easily share/update it.
The issue is that, sometimes, when someone clones the project and start using it the IDE doesn't care about that file (or project structure) and puts an .iml outside the project's root. It's an intermittent/random issue and I'm not able to reproduce it step by step.
We opted for deleting the .idea directory from Git and keep the configurations/settings in a JAR file.
Is there any way to tell the IDE to use one approach or the other? It's not a big deal, but I would like to know what's the reason behind that behavior.
The reason for that behavior may be that people don't use the "Open" action to open the project but use the "Import project from existing sources" action instead. The latter action does not use the existing .idea directory, but instead recreates the project structure from scratch. You should teach your colleagues not to use that action.
Note that storing the settings in a .jar file is not a replacement for sharing the project structure, because shared settings do not include project-specific items such as libraries and run configurations.

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.)

How can I manage a non-src module with intellij 13?

I recently switched from eclipse. With eclipse, I was used to have "non-src" projects (General->Simple Projects) in my workspace. They were pretty handy, since I could use them for version control of documentations, configure servers, ...)
Now with intellij, I am missing this feature. I only can import src modules into my project, otherwise I get the warning "nothing to import". Any idea how to trick intellij to accept a plain old file system directory?
Update:
To clarify, this is my setup:
root (trunk, sync with svn)
+- maven-project (root pom.xml)
|+- module a
|+- module b
|\- ...
+- documentation
|\- word/xls/...
\- server
\- jboss home dir
I sync (update) directly on "root" to keep everything together.
I imported the structure to intellij, but only got the "maven-project" (with all submodules), not "documentation" nor "server".
I would like to have the folders next to "maven-project" in my project structure. That way, I could easily edit server settings files within idea for example or add/commit new office files without using extra tools or cli.
Hope this helps to get the picture.
Unfortunately there is no kind of "Empty Module" or "Facet-less Module" in IntelliJ.
In such cases I just create a static "Web" project, as I think this is the least invasive type for modules, which doesn't need any facet:
File -> New Module
Static Web -> Web
At "Content Root" -> Point to your sources
Can you bypass the import feature and just create a new module, and then copy the contents in there?
Otherwise, do you really need a module at all? Folders can quite happily sit in the file structure of your intellij project without being modules.

How to generate a jar from a java module in IntelliJ with the dependencies placed in a separate directory?

I have a module for which I want a jar to be created. So, here is what I do:
Adding a jar artifact, using the "From module with dependencies ..." option
In "Jar files from libraries" I select "copy to the output directory and link via manifest"
Leave all the defaults.
After that I can build the jar and all the dependencies would be placed near it in the same directory. So far so good.
Now I wish all the dependencies to be placed in a separate directory near the final jar. So, I repeat the same steps, but this time I create a new directory under the node in the artifact Output Layout tab (using the "Create Directory" button). Next I drag all the dependencies onto the new folder and apply the changes.
On the surface, everything is cool - the dependencies are indeed placed in the dedicated directory, but the MANIFEST.MF file is never updated! It should reference the dependencies via the new directory. As of now, the produced jar cannot be run - its dependencies are not visible.
This is unlike Eclipse, which does make sure the manifest file is correct when exporting a project as jar.
How can I workaround this problem, given that:
I want all the dependencies in a dedicated folder.
I want to use IntelliJ IDEA
I do not want to edit the manifest file manually.
I am using the latest download of the IntelliJ IDEA for windows - 11.1.2, build 117.418
Thanks.
At the moment you have to update the classpath manually in the artifact configuration dialog so that it includes the subdirectory:
I've created an issue for this limitation, please star/vote.