11

I have a maven pom with profiles. In one of those profiles I refer to a system variable like this

<profile>
    <id>kasper</id>
    <properties>
        <user>${username}</user>
    </properties>
</profile>

When I invoke maven command line with the -Dusername=kasper all seems to be well.

The thing is, I import this project in IntelliJ. IntelliJ 13 allows to select profiles with which to run, through the Maven Tool Window.

When I select this specific profile to use while running tests, I can't seem to find how to replace this property correctly, i.e. to really tell IntelliJ that it has to pick this or that user name to run my maven tests, I tried a bit of everything and it doesn't seem to pick ot up.

Anybody an idea?

Kasper

3 Answers 3

10

In IntelliJ 14 maven profiles are not passed to tests (by default).

You can activate this mechanism via an option in Settings -> Maven -> Running Tests which let you enable passing of systemPropertyVariables to unit tests - this should cover your case.

2
  • 1
    This should be the correct answer because it works universally and describes root cause. I have also noticed change in IDEA behavior in version 14 in this regard.
    – Aries
    May 20, 2015 at 5:33
  • I am using IntelliJ 2016.1.3 and this option is enabled by default
    – Wojtek
    Jan 16, 2017 at 12:49
4

View -> Tool Windows -> Maven Projects then right clicking on needed phase, e.g. package it will be second item in context menu called *Create [project_name] package ...*

And on some tabs you could override VM properties, add profiles, etc.

3
  • Thanks, that did the trick indeed, fiddled around with all kinds of options but didn't think of right clicking on that life cycle thingy.
    – Kasper
    Apr 2, 2014 at 6:56
  • Euhm, I didn't get it completely I guess. When I make one of these run configurations the arguments (test in my case) the arguments I fill out indeed get picked up by the JUnit configuration, which is what I want, I can then debug and so on, but it seems to be very picky when it applies and when not (for example if I make a new junit run configuration I need to remake the maven configuration). How is the link between the maven configuration and the junit configuration exactly?
    – Kasper
    Apr 2, 2014 at 7:30
  • @Kasper, not sure that this link exist. You better need to ask another question ;)
    – Mysterion
    Apr 2, 2014 at 7:46
3

OK, I got it.

Go to the Intellij configuration on JUnit or TestNG (whichever one you are using). Under VMoptions... you can add the custom system property variables from Maven to debugger beside -ea option just like terminal command.

-ea -Dtest.environment=QA

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.