How to Script Installation and Activation of Custom Inspection Profiles
Background/Situation
In team environments, the shared inspection profile (Project_Default.xml) is often committed to version control in .idea/inspectionProfiles/. However, individual developers may want to use custom inspection profiles with different settings without modifying the team's controlled version and causing changes to appear in git diff.
This situation is common when:
- Development VMs are frequently rebuilt or refreshed, and an automated setup is needed
- Personal inspection or code style preferences differ from team defaults
- Manual GUI configuration steps during project setup need to be avoided
Question
Can custom inspection profiles be scripted for installation and activation?
Specifically:
- How can a custom IntelliJ inspection profile be programmatically "imported" or "applied"?
- How can IntelliJ be automatically "switched" to use a custom profile without manual GUI interaction?
- How can code styles be automated for import into
.idea/codeStyles/? - How can this be done without creating Git conflicts with the team's shared configuration?
Answer
While there is no officially documented command-line API for switching inspection profiles, the activation of custom profiles can be automated by managing IntelliJ project configuration files directly.
Scripting Inspection Profile Activation
The active inspection profile is controlled by profiles_settings.xml in the .idea/inspectionProfiles/ directory.
Steps:
- Create a custom inspection profile XML (e.g.,
custom_profile.xml) in.idea/inspectionProfiles/ - Create or modify
profiles_settings.xmlin the same directory:
<component name="InspectionProjectProfileManager">
<settings>
<option name="PROJECT_PROFILE" value="custom_profile" />
<option name="USE_PROJECT_PROFILE" value="true" />
</settings>
</component>
Important: The PROJECT_PROFILE value must match the name attribute in the custom inspection profile XML file (without the .xml extension).
Scripting Code Style Activation
Code styles are controlled by codeStyleConfig.xml in the .idea/codeStyles/ directory.
Steps:
- Place a custom code style XML file (e.g.,
CustomCodeStyle.xml) in.idea/codeStyles/ - Create or modify
codeStyleConfig.xml:
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
</state>
</component>
Avoiding Git Conflicts
To prevent personal configurations from affecting version control:
Option 1: Use .gitignore
- Keep the team's
Project_Default.xmlin version control - Add personal profile files to
.gitignore:
.idea/inspectionProfiles/custom_profile.xml
.idea/inspectionProfiles/profiles_settings.xml
.idea/codeStyles/CustomCodeStyle.xml
.idea/codeStyles/codeStyleConfig.xml
- Setup scripts install these files during environment setup
Option 2: Store personal configs externally
- Maintain personal configuration files in a separate location (e.g.,
~/intellij-configs/) - Script their installation into the project
.idea/directory - The repository only contains the team's default configurations
Automation Script
Here's a bash script to automate the setup:
#!/bin/bash
# Script: setup-intellij-profiles.sh
# Purpose: Install custom IntelliJ inspection profiles and code styles
PROJECT_DIR="."
CONFIG_SOURCE="$HOME/intellij-configs"
# Ensure directories exist
mkdir -p "$PROJECT_DIR/.idea/inspectionProfiles"
mkdir -p "$PROJECT_DIR/.idea/codeStyles"
# Install custom inspection profile
echo "Installing custom inspection profile..."
cp "$CONFIG_SOURCE/custom_profile.xml" "$PROJECT_DIR/.idea/inspectionProfiles/"
# Activate the custom inspection profile
cat > "$PROJECT_DIR/.idea/inspectionProfiles/profiles_settings.xml" << 'EOF'
<component name="InspectionProjectProfileManager">
<settings>
<option name="PROJECT_PROFILE" value="custom_profile" />
<option name="USE_PROJECT_PROFILE" value="true" />
</settings>
</component>
EOF
# Install custom code style
echo "Installing custom code style..."
cp "$CONFIG_SOURCE/CustomCodeStyle.xml" "$PROJECT_DIR/.idea/codeStyles/"
# Activate the custom code style
cat > "$PROJECT_DIR/.idea/codeStyles/codeStyleConfig.xml" << 'EOF'
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
</state>
</component>
EOF
echo "Custom IntelliJ settings applied successfully!"
echo "Open the project in IntelliJ IDEA to use the custom profiles."
Usage:
- Store custom profile XMLs in
~/intellij-configs/ - Run this script after cloning the repository:
./scripts/setup-intellij-profiles.sh - Open the project in IntelliJ IDEA - the custom profiles will be active
Workflow for Frequent VM Refreshes
For environments where VMs are rebuilt frequently:
- Initial setup: Export preferred profiles once and store them in a known location
- Add to VM setup automation:
# Part of VM setup script
cd /path/to/project
./scripts/setup-intellij-profiles.sh
- No manual GUI interaction required - IntelliJ will automatically use the custom profiles
Important Considerations
Tested in IntelliJ IDEA 2025.2.3
⚠️ Unsupported Approach: This method is not officially documented by JetBrains and relies on the internal structure of IntelliJ configuration files. While this approach is used in production projects, it could potentially change in future IDE versions.
✓ Project vs IDE Settings: These configuration files (profiles_settings.xml and codeStyleConfig.xml) are project-level settings stored in .idea/. They are separate from workspace settings and can be managed through version control or excluded as needed.
✓ Team Impact: This approach does not affect other team members. The team's Project_Default.xml remains unchanged in version control. When teammates clone the repository without the personal configuration files, IntelliJ uses the default team profile.
Alternative Approach: IDE-Level Profiles
To avoid project-level configuration entirely, IDE-level profiles can be used:
- Store profiles globally in the IDE configuration directory
- Configure once per IDE installation, not per project
- Profiles persist across all projects
- No interaction with project version control
However, this requires manual GUI setup once per VM rebuild.
Alternative for Code Styles: EditorConfig
For code style settings, .editorconfig files can be considered:
- Automatically recognized by IntelliJ IDEA
- Can be version-controlled alongside code
- Provide language-agnostic coding style definitions
- No XML configuration required
- Widely supported across different editors and IDEs
See Also:
Comments
0 comments
Please sign in to leave a comment.