Automatically add a set .gitignore file to a New Project folder location when creating a New Project in IntelliJ - intellij-idea

I would like to have a certain .gitignore file created in the directory of a New Project when I create it in IntelliJ. Is there a way to set this up to automatically happen?

You can use project templates for that. See https://www.jetbrains.com/help/idea/saving-project-as-template.html

Related

PhpStorm : Use files from one project in other projects without copying them?

I have one project which contains some PHP services that I use as a template in all my other projects.
Is it possible to add these files to a new project without actually copying them to the new project's directory? Or, they could be copied but I want changes to one of the copies to affect the template.
For example. Template project contains
folder service with files "1.php", "2.php", "3.php"
and folder util with "u1.php" and "u2.php".
I want to use these files in one or more new projects but without copying them.
They should merge with the files of the new project and be treated as if they are in the new project's directory.
If the new project also has a folder "service" with files "4.php" and "5.php" the files 1 2 and 3 from the template should show there too.
And if I were to edit service/1.php in the new project, the original file in the template project would get changed as well.
Is something like this possible?

open a directory with intellij without creating a project

I want to be able to open a directory with intellij without creating a project.
how to do it?
every time I open a folder, a project is automatically created with an .idea folder
When you use the Intellij IDE to open a directory,
It assumes that you are going to open a project (as it is the main reason to use IDEs). By default all of jetbrains's IDEs put the project specific settings for project in the .idea folder.
It is also safe to delete it if you are just opened a directory. There would be no problem in deleting this.
You can also use Terminal tab to change or open a directory (Alt+F12)
and use terminal commands to traverse between directories without creating any .idea folder.

How can I clone a whole project in IntelliJ Idea?

I want to run some tests in my project but I do not want to affect the
original code, and I wanto to clone the project so I can run tests there
Does anyone know how to clone a project on IntelliJ Idea 11?
Using your operating system File Explorer tool, just copy and paste the entire project directory somewhere new. All of the configuration should use relative paths by default.
If your IDEA project is .ipr based, then delete the new .iws file before opening the project.
If your IDEA project is .idea directory based, then delete the workspace.xml file before opening the project.
If you want to copy and rename the project too, like I wanted to clone a project in order to use it with a newer version of IntelliJ.
Copy the whole directory to a new location, for example on Linux:
cp -r myproject new/location/
To rename the project:
2.1. rename the project folder (e.g. mv myproject newproject)
2.2. get into the new project folder (e.g. cd newproject) and edit the .name file with a text editor.
Open the new project now in IntelliJ (you may want to remove the workspace.xml if you don't want to keep the open file history - I kept it) and enjoy your new project!
For copy with rename I had to do one more step to get it to stop referencing the old module name. That was to right click on the module in the project pane and do Refactor > Rename ( or do Shift + F6 ) to rename the module.
This was for IntelliJ IDEA 2016.3.3
I had a gradle project and the provided answers did not work. The project did not have a structure in IntelliJ and I did not see the source files.
The following worked:
Export project (Export to zip file)
Move the zip file somewhere new
Unzip
With IntelliJ, import as a new project with "open".
Better Solution of course:
Have it in a git directory, make a "test-branch" and try whatever you want to try.
Apparently the accepted answer doesn't work anymore with current versions of Idea and the many derived IDEs (I tried this with PHPStorm). The problem: most of the config files are located in the .idea subdirectory of your project, but the file .idea/workspace.xml also contains the ProjectId, and that should of course be unique. So, if you copied the project directory manually, the easiest fix is to change the ProjectId - from what I have seen you can enter any alphanumeric string, e.g. "ProjectId123".
As far as I can see the main settings that are stored under the ProjectId are the workspace settings, under ~/.config/JetBrains/[IDENameAndVersion]/workspace/[ProjectId].xml. This file mostly contains the open editor tabs (with paths relative to the project directory) and the tool windows, so if you copy the project directory, you will always have the same editor tabs open in both projects (containing the "same" files, but from the respective project). If you want to avoid opening all files and setting up the tool windows, you can copy the old [ProjectId].xml file to e.g. ProjectId123.xml (using the ProjectId that you entered earlier).
After Copying your existing Project to a new folder don't forget to mark your src directory as Source directory. You can do this under Project Structure | Modules.
To duplicate and rename a CLion cmake project I followed the info in the other answers with some tweaks.
What seems to be the stepless way to eliminate all references to the old project name in the new one (tested with CLion 2019.1.2):
Copy folder
rename the new folder
On the new project folder:
delete the project info folder (CLion will recreate it):
<new project name>/.idea
On a text editor, open:
<new project name>/CMakeLists.txt
change every reference to the old project name with the new name and save it.
This will assure CLion will not use Project and Target info in "CMakeLists.txt" file to recreate project files and data in ".idea" folder with the old name.
Note that other info in this file referencing the old project folder, or files stored there, such as INCLUDE, SOURCE directories, and files, should also be changed to point to the new folder.
delete old compile data. Delete folders like:
<new project name>/cmake-*
Open project in CLion
It should have the new name and no reference to the old name anywhere.
If using CSV, you may also wish to delete old CSV data
EDIT: If project requires CUDA, CUDACXX environment variable must be reassigned to full path of nvcc compiler:
File->settings->Build, Execution, Deployment->CMake->Environment
IF CLion CUDA Run Patcher is installed it maybe needed to restart CLion.

How to add non-source folders to IntelliJ IDEA project

Recently set up a multi module project in IntelliJ with the following structure:
/module1
/module2
/web-module
/sql
/lib
/a few more folders
I set up module1+2 and web-module as modules in IntelliJ so those show up, but how do you make the sql and lib folder show up in the project panel? They should be included in VCS as well, but IntelliJ ignores them. How do you add folders outside modules to a project?
Screenshot of project and explorer view:
This is not a strict answer to the question, but it worked for me so I'm posting, perhaps someone will find this useful.
If you want to add an arbitrary folder to your project (even from some different location than your projects), just add it as a module. You needn't worry about the type so much e.g. I needed to add a folder with some SQL scripts, I added it as a Java module and it's nicely visible in IntelliJ even though it has no maven structure or Java sources.
This is how to do it:
File > Project Structure > Modules
Add > New Module > ... (e.g. Java Module)
In the new module settings mark the subfolders that you want to see as 'Sources'
VoilĂ ! :)
This is something that I typically see when creating a project from existing modules. All the modules will show in the project but not the other project related directories. These directories might be, configuration files, environment scripts or bundles of SQL scripts that don't fit neatly into an Intellij module type.
To show the rest of the project source files and directories, I create a parent module from the project root.
File->Project Structure->Modules
Create a new module using the + sign. The new module could be any type (I use java).
On the Next screen set the Content root and Module file location to the Project's root folder.
Select Finish
All of your other modules should now be submodules of the root, and your other project files should now show up.
Add and remove content roots
To add a new content root:
Go to File | Project Structure, or press Ctrl+Shift+Alt+S.
Select Modules under the Project Settings section.
Select the necessary module, and then open the Sources tab in the right-hand part of the dialog.
Click Add Content Root.
Specify the folder that you want to add as a new content root, and click OK.
source: https://www.jetbrains.com/help/idea/creating-and-managing-modules.html
I used File -> New -> Module from Existing Sources...
Then I simply select the folder and add it.
In Project view mode all directories (except the ignored ones from the settings) should show up. Of course the base folder for your multi-project has to be the folder above module1.
EDIT:
Your project should look like this (project view tree):
MY_PROJECT_ROOT (~/the/folder/to/your/project)
|- /module1
|- /module2
|- /web-module
And in this case, you should definitely see the other folders. I got a sample project set up where this is working.
EDIT 2:
From your screenshot, I assume you are missing the root directory (the project root is not as you expected). I added another screenshot. There should be a single root folder for your 3 modules. This one is missing at your screenshot. You have 3 separate folders with no common root folder. On MacOs, the project root is displayed in the window title. In my case it points to ~/devel/sandbox.
I guess you should try to create a new project in for that trunk folder. From the scratch. Then add the existing modules and you should be fine?!

intellij idea run configurations backup

I would like to create a script to modify my debug configuration in intellij. The path of tomcat changes, and i have to manually go into the run config and edit things. I have tried to find the place where intellij stores these settings to no avail.
question: does anyone know where IJ stores its run configuration
The location would depend on 2 factors, whether the configuration is local to the user or shared with the other developers and if you are using the file based (legacy) or the directory based project format.
File based project, local configuration: .iws file
Directory based project, local configuration: workspace.xml file under .idea directory
File based project, shared configuration: .ipr file
Directory based project, shared configuration: .xml file under runConfigurations subdirectory of .idea directory or files inside .run directory in the project root (you can customize the location of the shared configurations in the latest versions).
Its here .idea\runConfigurations (correct for Idea 11). Just copy this folder to new project.
EDIT: As per comment, if runConfigurations folder doesn't exist, check the 'Share' box inside the Run/Debug configuration