Automatically activate maven profile in Intellij IDEA
Asked Answered
C

2

5

Is there a way to automatically activate a maven profile when the project is opened in IntelliJ IDEA?

For eclipse, this can be done by using the property m2e.version for activation and I thought there may be something similar for IDEA.

<profiles>
    <profile>
        <id>m2e</id>
        <activation>
            <property>
                <name>m2e.version</name>
            </property>
        </activation>
        <build>
            <directory>${project.basedir}/eclipse-target</directory>
        </build>
    </profile>
</profiles>

What I basically want, is to have a separate build directory for IDEA. This is useful to run mvn commands on the command line without messing with the IDE.

Chiefly answered 28/8, 2014 at 13:42 Comment(2)
What is the reason or better why do you need such things?Ghee
As mentioned in the question, it's very handy to have two different target directories - one for the IDE and one for mvn on the command line. So you can run mvn commands on the command line without interfering with your IDE (e.g. running mvn clean package while your're debugging the webapp in your IDE).Chiefly
T
7

IntellJ sets the idea.version property when running maven run configurations. It also sets this property while detecting default profiles when importing a maven based project.

    <profile>
        <id>activeInIdea</id>
        <activation>
            <property>
               <name>idea.version</name>
            </property>
       </activation>
       <build>
            <directory>${project.basedir}/eclipse-target</directory>
       </build>
    </profile>

After opening the project in IntelliJ the profile (in the example above called activeInIdea) is already pre-selected.

Torritorricelli answered 21/6, 2016 at 13:58 Comment(1)
I had to use idea.maven.embedder.version instead of idea.version when I tried on IntelliJ IDEA Ultimate 2020.2.3Gimbals
M
0

When imported as Maven project, IntelliJ will detect your maven profiles and import them as well. It will allow you to activate profiles on import and will even enable profiles which appear enabled during import. You can toggle the profiles after import in the Maven Projects tool window.

If your question aims on how to save you one click to activate the profile, then I haven't answered your question. But if you just missed the Maven Projects window, then here you go.

Mikkanen answered 14/1, 2015 at 9:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.