IntelliJ IDEA 2019.1 Help

Work with 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.

    maven profile declaration
    IntelliJ IDEA displays them in the Profiles list of the Maven Projects tool window.
    maven tool win declared profiles

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.0. See Maven 3 compatibility notes.

Activate Maven profiles

When IntelliJ IDEA imports a Maven project, it detects profiles and lets you activate them during importing.

  1. Start importing your Maven project.

  2. In the Import from Maven page where IntelliJ IDEA displays the profiles, activate the ones you need.

    maven import proj select profiles

  3. Click Next and finish your import.

You can activate a profile manually in the Maven Projects tool window using a -P command or using the Profiles node and the corresponding profiles' checkboxes.

  1. Open the Maven Projects tool window.

  2. On the toolbar, click the maven goal icon icon.

  3. In the dialog that opens, in the Command line field, enter -P and the name of your profile. If you need to exclude certain profiles, specify ! in front of the name of the profile. The profile will be excluded even if it is activated by default. Click OK.

Alternatively, you can use Profiles node in the Maven Projects tool window to activate profiles.

  1. Open the Maven Projects 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 of the parameters inside your POM.

You can make a Maven profile to be activated automatically by default if you declare such profile with the activeByDefault tag in the POM.

maven profiles pom
IntelliJ IDEA displays the activeByDefault profile in the Maven Projects tool window with the selected checkbox that is greyed out.
maven proj tool win profiles
You can manually de-activate this profile by clicking the checkbox. Also note that if you manually activate any other profile, the activeByDefault profile will be de-activated.
maven tool win 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 de-activated when you manually activate any other profile even if it is declared in the POM of a different module.

Last modified: 20 June 2019