P4CONFIG and IntelliJ IDEA

IntelliJ IDEA has good support for Perforce, you can go to “Settings” => “Version Control” => “Perforce” to configure Perforce settings:

p4-settings

However, if you have many projects that are hosted in Perforce depots, you have to do this for each individual project. Is there a global setting that you can configure to avoid this manual work over and over? The answer is yes, you can utilize P4CONFIG to set default Perforce configuration.

P4CONFIG is an environment variable that contains the name of P4CONFIG file without a path.

p4-variable

Once defined, you should create a p4config.txt file. A sample might consist of such lines:

P4CLIENT=Harvey.Shen
P4USER=Harvey.Shen
P4PASSWD=Your_Perforce_Password
P4PORT=p4.fuzzyinfo.net:1666

Note that P4PORT is a misnomer, it should contain both the perforce host and port, separated by ‘:’.

There’s another parameter P4HOST you can add into configuration file, but it doesn’t mean perforce host, it’s the name of the host computer to impersonate. In another word, this should your computer’s hostname. If you accidentally set perforce server hostname here, you will receive error like ‘xxx client can only be used from host host_name’. For details, check Perforce doc. So the best strategy is to leave this undefined, your computer’s host name will be used automatically as P4HOST. In certain case that your client is bound to one host name, then you can define this variable.

Once p4config.txt  file is created, save it to perforce workspace. You might ask the question, where?

The answer depends on your need, if you like me, all projects store in the same perforce depot, just store this file under the parent folder of all your perforce projects, for example: C:p4Harvey.ShenHarvey.Shenp4config.txt

IntelliJ IDEA seeks for P4CONFIG file in project directory and its parents. So putting the configuration file in parent directory will ensure all projects to use the same configuration.

However, if your projects are stored in the different Perforce depots, you might need to switch between them. Then you should define multiple p4config.txt, one for each project, then save it under project directory. The IntelliJ will be able to connect to the respective Perforce depot. For details, check this out.

After you save the p4config.txt, you can configure your perforce in IntelliJ IDEA

p4-settings-configuration-file

Remember to click ‘Test Connection’ button, IntelliJ IDEA will show what configuration file it has found and what other default settings are used. This way you can be sure that your P4CONFIG files are found and taken into account. Moreever, in case your configuration was wrong, IntelliJ will prompt you the errors. For more details, refer to here.

 

(Visited 147 times, 1 visits today)