When I execute certain goals from the command line I would like to activate a profile 'automatically'.
E.g. what I'm doing now:
mvn appengine:devserver -Pdevelopment
mvn appengine:update -Pproduction
Basically I want to activate the development profile automatically as I run the devserver goal. The same for the production profile which I want to activate when I run the update goal (unless explicitly overridden using -P option).
Is this possible?
The Maven Model told us as the profile consists of various elements, including with build. as the following example: -
As we have seen above, the
profile
controls theplugin
. Then the answer to your question is no. We cannot let theplugin
to activate theprofile
.I hope this may help.
I agree with the previous conclusion that you cannot do this. The reasoning I saw before may be slightly backward.
The plugin is activated by defining the goal on the command-line (in the specific case of this question), not by the plugin being in the profile.
It is probably plugin default configuration (
plugin.configuration
) that you're trying to override this way, rather than the configuration for a specific execution (plugin.executions.execution.configuration
). And that fine by me. But the pickle is to get the profile activated.If all you're having on your command-line is the goal (e.g.
appengine:update
) there's no way that's gonna activate a profile.When you read discussions about profile activation (as I stubbornly did a lot in the past) you'll find that there is a lot still desired by many people in terms of profile activation. Activating profiles on basis of what goals are executed is not even a desire that I yet came across — just to say: don't get your hopes up.
You may also wonder whether what you're trying to do is really appropriate. Do you really need to run goals, or could you somehow still benefit from the Maven lifecycle?
The Maven lifecycle is really a (straight) path to completion, traversing through phases. If you want to divert this path based on certain conditions, profiles are the way to go. If
appengine:update
andappengine:devserver
are "either/or" (which I believe they are) you're diverting the path, should use profiles, really, and will still end up with having at least two things on your command-line, i.e. the phase and the desired profile. If there's one typical case and one exceptional case you could express that by default profile activation (activeByDefault
) and explicitly choosing another profile (-P
) respectively:If you want to do both (e.g.
devserver
during integration test phase andupdate
during deploy) the lifecycle can be configured to do so through pluginexecutions
that are tied to aphase
subsequently. You will simply have one thing on your command-line, i.e. the phase.