IntelliJ IDEA 2024.1 Help

Maven profiles

IntelliJ IDEA lets you use Maven build profiles which can help you customize builds for a particular environment, for example, production or development.

Declare Maven profiles

IntelliJ IDEA lets you declare profiles explicitly in the POM of your project. Using code completion, you can place a number of different configurations inside the profiles tags and override the default configurations specified in your POM for Maven plugins, dependencies, repositories, and so on.

  1. Open your POM in the editor.

  2. Specify the <profiles> section and declare the profiles.

    Profile declaration

    IntelliJ IDEA displays them in the Profiles list of the Maven tool window.

    Maven tool window

Alternatively, you can declare profiles using one of the following ways:

  • You can define them locally in the Maven settings directory %USER_HOME%/.m2/settings.xml.

  • You can define them globally in the global Maven settings ${maven.home}/conf/settings.xml.

  • You can define them in the profile descriptor located in the project's base directory (profiles.xml). Note that this option is not supported in Maven 3. See Maven 3 compatibility notes.

Activate Maven profiles

You can activate a profile in the Maven tool window using the Profiles node and the corresponding profiles' checkboxes.

  1. Open the Maven tool window.

  2. Click the Profiles node to open a list of declared profiles.

  3. Select the appropriate checkboxes to activate the profiles you need. You can have several active profiles. When they are activated, their configurations are merged based on the POM profile declaration.

You can also activate profiles automatically according to a range of contextual conditions, for example, JDK version, OS name and version, presence or absence of a specific file or property, but you still need to specify all the parameters inside your POM.

You can declare a Maven profile with the activeByDefault tag in the POM that activates only if Maven doesn’t find any other active profiles. For more information, refer to Maven profiles.

POM: profile activation

IntelliJ IDEA displays the activeByDefault profile in the Maven tool window with the selected checkbox that is greyed out.

the Maven tool window: selected profile

You can manually deactivate this profile by clicking the checkbox. Also note that if you manually activate any other profile, the activeByDefault profile will be de-activated.

the Maven tool window: deactivate profile

When you work with multi-module projects, keep in mind that if you specified the activeByDefault profile in your POM it will be deactivated when you manually activate any other profile even if it is declared in the POM of a different module.

Last modified: 08 April 2024