IntelliJ allows you to configure the "File and Code Templates" in Settings.

This is a global setting, however I want different templates depending on which project I am working on (for example there will be different @author tags if its commercial / open source work, and version information varies by project).

Eclipse manages this on a per-workspace basis; how can I achieve the same thing in IntelliJ IDEA?

有帮助吗?

解决方案

Unfortunately per project templates are not supported in IntelliJ IDEA. I recommend you comment-on/vote-for/track the feature request Make file templates per-project. (See UPDATE about this feature request below)

A few workarounds you can try...

Create a File Template for each project. Then when you create a new class, use the project's template rather than the standard "Java class" template. It will clutter up your template list a bit, and you have to remember to change from the default template when creating a new class (remember than inline search is available in the new class dialog when setting the type). But it is workable.

The copyright settings are done on a per project basis. Sometimes a need for a specific header can be met using the copyright utility (even if it is not an actual copyright statement). The options are pretty good for determining where it gets placed. The one shortcoming will be that while you can configure it to be a comment just before the class declaration, you can only configure to be a block comment or inline comment, not a javadoc comment.

Finally, a last option would be to write a live template for each project with the header information. Then after you create a class use the proper one to place the header information.

Hopefully those things will help while we wait for the feature to get implemented.

UPDATE

The above mentioned feature request to allow for file templates to be saved on a per project basis has been implemented in IDEA v14.1. It is currently (Feb 2015) available as an EAP (i.e. beta). It is scheduled for release at the end of Q1 2015.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top