Customizing IntelliJ IDEA File Headers
This guide explains how to customize file headers in IntelliJ IDEA using Groovy scripts to dynamically generate file header information for different projects, thereby improving code maintainability and team collaboration efficiency.
- 3 min read
- 2026.08.04
IntelliJ’s file header templates are configured under Settings → Editor → File and Code Templates → Includes → File Header. By using a Groovy script to check the package prefix ${PACKAGE_NAME}, you can automatically generate different file headers for personal and company projects.
IntelliJ IDEA File Header Custom Configuration
🎯 Background
In the software development process, the File Header contains the definition and original intent of a project or file. A well-written File Header helps future developers quickly understand the design intent and background information of the code.
The Purpose of the File Header
As the first part of a file, the file header typically includes the following basic information:
- Author Information - Identifies the creator of the code
- Creation Date - Records when the file was created
- File Description - Explains the file’s functionality and purpose
- Copyright Notice - Protects intellectual property
- Version Information - Tracks changes in file versions
- Project or Module Name - Identifies the project to which it belongs
- Contact Information - Facilitates future communication
By standardizing file headers, team members can quickly understand the file’s creation context and author, improving code maintenance efficiency—especially when working on complex or long-standing projects.
📝 File Header Example
The following is an example of a standard Java file header:
/**
* Author: CassianFlorin
* Created: 2025-05-20
* Description: This class implements the user authentication logic.
* Version: 1.0.0
* License: MIT License
*/
public class AuthService {
// Class implementation
}
⚙️ File Header Configuration Steps
1. Access the Configuration Interface
In IntelliJ IDEA, navigate to the configuration via the following path:
File → Settings → Editor → File and Code Templates → Includes → File Header
2. Configuration Interface Overview
- File and Code Templates: Settings for file and code templates
- Includes: Included template files
- File Header: File header templates
🚀 Dynamically Generating Headers Using Groovy Scripts
To distinguish between file headers for personal and corporate projects, I use Groovy scripts to dynamically generate different header information.
Configuration Script
#if(${PACKAGE_NAME.startsWith("[公司的包路径]")})
/**
* @Author [公司要求的名称]
* @Email [公司邮箱]
* @Date ${DATE} ${TIME}
*/
#else
/**
* @Author CassianFlorin
* @Email flowercard591@gmail.com
* @Date ${DATE} ${TIME}
*/
#end
Script Description
- **
${PACKAGE_NAME}**: Retrieves the package name of the class being created - **
${DATE}**: Current date - **
${TIME}**: Current time - Conditional Check: Determines whether the project is corporate or personal based on the package prefix
How It Works
In enterprise-level development, package names typically follow the "reverse domain name" convention (e.g., com.company.project ). Therefore, by examining the package prefix, we can distinguish between different project types and generate the corresponding file header information.
💡 Suggestions for Expansion
There are various configuration methods. In addition to simple Groovy scripts, you can also:
- Use more complex conditional checks
- Integrate project information
- Add additional metadata
- Customize formatting styles
If you’d like to learn more about configuration options, feel free to reach out!
> Tip: The specific content and format of the File Header can be adjusted according to your team’s guidelines and project requirements.