views:

121

answers:

2

I'm trying to let maven run a single test class but I need to use an additional profile (which in fact is already created). Normally when I run:

mvn clean install -PmyProfile

"myProfile" is being activated. So I tried:

mvn -Dtest=myTest -PmyProfile test

Which resulted in "[WARNING] Profile with id: 'myProfile' has not been activated."

What am I doing wrong and how can I achieve my goal?

A: 

I believe you need a space after the -P before you list the profile(s) you would like. The documentation also always uses that argument at the end of the command. Try:

mvn -Dtest=MyTest test -P myProfile

For more info on using profiles: Introduction to build profiles

Gweebz
Using `-Pmyprofile` is valid.
Pascal Thivent
downvote is not mine by the way
Pascal Thivent
@Pascal - no worries either way; the answer is wrong, I expected a hit. ;) I probably should have tried it first LOL
Gweebz
+2  A: 

I cannot reproduce. I have a "sandbox" profile defined in my ~/.m2/settings.xml and the following command just works, without complains:

$ mvn -Dtest=AppTest -Psandbox test
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Q3372129
[INFO]    task-segment: [test]
[INFO] ------------------------------------------------------------------------
...

While using an undefined profile generates the WARNING you're talking about:

$ mvn -Dtest=AppTest -Pfoo test
[INFO] Scanning for projects...
[WARNING] 
    Profile with id: 'foo' has not been activated.

[INFO] ------------------------------------------------------------------------
[INFO] Building Q3372129
[INFO]    task-segment: [test]
[INFO] ------------------------------------------------------------------------
...

This begs the question: where is this profile defined?

Pascal Thivent
myProfile is defined in my pom.xml. I didn't think of defining profiles in my settings.xml. Thanks a lot for your response.
Jeroen Rosenberg