Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Activate certain Maven profile in Intellij IDEA only

I'm looking for a way to activate the certain profile, which includes some dependencies and settings, related to the development mode only, when the project is opened in IDEA.

I know that you can specify the profile to be used - on project import, or in "Maven projects" tab. However it requires some interactions, which are easy to forget.

So it would be nice to instruct idea to always activate the appropriate profile, may be by providing some property or runtime configuration, or whatever.

This profile should be active only for IDEA import.

like image 344
jdevelop Avatar asked Jul 15 '14 14:07

jdevelop


People also ask

How do I run a custom Maven command in IntelliJ?

From the main menu, select Run | Edit Configurations to open the run/debug configuration for your project. In the list that opens, select Run Maven Goal. In the Select Maven Goal dialog, specify a project and a goal that you want to execute before launching the project. Click OK.


2 Answers

For auto-activation of the profile, you can base the activation on a system property that is only present when running through the IDEA embedded Maven:

  • idea.maven.embedder.version
  • idea.version

Example:

<profile>
    <id>idea-only</id>
    <activation>
        <property>
            <name>idea.maven.embedder.version</name>
        </property>
    </activation>
    ...
</profile>

idea.maven.embedder.version works with IDEA's bundled Maven and also works if you override that with your own locally installed version of Maven in preferences - the idea.maven.embedder.version property is always set when executed from within the IDEA when importing, generating sources, etc.

like image 141
prunge Avatar answered Oct 04 '22 08:10

prunge


If you import a maven project in intellij, you can choose profiles in the maven tool window (usually on the right of the screen). Once these profiles are selected they will persist in the project configuration for that project and will become effective every time the project loads, until you choose to change them. These profile selections will only affect intellij and instances of maven run within intellij.

Another way to achieve this is in Intellij's maven configuration, by specifying a settings file that is specific to intellij development. This can be a copy of your standard settings, named something like intellij-settings.xml, but you can add an active profiles section to it:

<activeProfiles>
  <activeProfile>intellij-specific-profile</activeProfile>
</activeProfiles>

Be sure to specify the settings file in your intellij maven config before importing the project. That way it will apply to all projects on import.

like image 22
Software Engineer Avatar answered Oct 04 '22 10:10

Software Engineer