How to activate profile based on goal being executed

后端 未结 2 1791
[愿得一人]
[愿得一人] 2021-01-12 11:51

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:devs         


        
相关标签:
2条回答
  • 2021-01-12 12:27

    The Maven Model told us as the profile consists of various elements, including with build. as the following example: -

    <profile>
        <id></id>
        ...
        <build>
            <plugins>
               <plugin></plugin>
               ...
            </plugins>
        </build>
    </profile>
    

    As we have seen above, the profile controls the plugin. Then the answer to your question is no. We cannot let the plugin to activate the profile.

    I hope this may help.

    0 讨论(0)
  • 2021-01-12 12:53

    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 and appengine: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:

    mvn deploy // choose default profiles
    mvn deploy -Pproduction // ignore default profiles
    

    If you want to do both (e.g. devserver during integration test phase and update during deploy) the lifecycle can be configured to do so through plugin executions that are tied to a phase subsequently. You will simply have one thing on your command-line, i.e. the phase.

    0 讨论(0)
提交回复
热议问题