maven-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Aliaksei Lahachou <aliaksei.lahac...@gmail.com>
Subject Re: How do I de-activate a profile if another profile is specified?
Date Fri, 09 Aug 2013 17:45:13 GMT
Hi!

One profile may not deactivate another profile. Maven should know the list
of active profiles before building the model. Profile activation is done on
very low level, almost on XML level during building the model. Once the
model is built, you cannot de/activate a profile, because you will have to
rebuild the model completely. There is also another problem: if one profile
could de/activate another profile, that would make it possible to introduce
cyclic dependencies between profiles.

Two options were already noted here:
* Set one profile to activeByDefault; it will be automatically deactivated
when another profile is activated.
* Use property to activate one account and !property to activate another;
you will have to activate your account by specifying -Dproperty in the
command line. I personally dislike this method, but that's the matter of
taste, there's nothing wrong with it.

There is another way, which is my favorite. It may or may not work for you,
depending on what's happening in your profiles. The idea is to remove
default profile completely. Define default behavior in main section, and
override it in profiles as needed. For example:

<project>
   ...
   <properties>
      <property>default value</property>
   </properties>
   ...
   <profiles>
      <profile>
         ...
         <properties>
            <property>specific value</property>
         </properties>
      </profile>
   </profiles>
</project>

You can actually do a lot of things with this approach:
* Redefine dependency versions, scopes, or even group or artifact ids.
Define a property with dependency id, set default value in main section and
override it in profile. Use this property in dependency declaration.
* Redefine plugin versions or parameters. Same as above.
* Activate or deactivate plugin executions. Many plugins have skip
parameter, you may use a property to set it to true in main section, and
set it to false in profile (or vica versa).

I prefer this method, because it produces smaller POMs. For example, I
don't have to declare a dependency in profile again, only to redefine its
version or scope. Same goes for plugins and plugin parameters.

Besides, it is possible to override any property in command line, which is
very helpful at times. For example, I always define properties for plugin
versions, and I can override plugin version in command line for testing
purposes without editing the POM.

Hope it helps.

Regards,
htfv (Aliaksei Lahachou)


On Fri, Aug 9, 2013 at 1:43 AM, SARTAJ HUNDAL <vektor.knight@gmail.com>wrote:

> On 13-08-08 03:40 PM, Robert Scholte wrote:
>
>> Ths is a good example for "activeByDefault" as described at
>> http://maven.apache.org/ref/3.**1.0/maven-model/maven.html#**
>> class_activation<http://maven.apache.org/ref/3.1.0/maven-model/maven.html#class_activation>
>>
>> "If set to true, this profile will be active unless another profile in
>> this pom is activated using the command line -P option or by one of that
>> profile's activators.
>> Default value is: false."
>>
>> Robert
>>
>> Op Thu, 08 Aug 2013 23:35:58 +0200 schreef Curtis Rueden <
>> ctrueden@wisc.edu>:
>>
>>  Hi Dave,
>>>
>>>  I want to activate a profile (profileA) at all times unless the user
>>>> specifically requests profile B on the command line
>>>>
>>>
>>> I didn't look at the Maven source code, but I am guessing all profile
>>> activations are evaluated before any activations actually take place?
>>> That
>>> would an intuitive way to code it, anyway.
>>>
>>> As a workaround, you could do:
>>>
>>>                 <profile>
>>>                         <id>recreateTestDbON</id>
>>>                         <activation>
>>>                                 <property>
>>> <name>recreateTestDb</name>
>>>                                 </property>
>>>                         </activation>
>>>                         ...
>>>                 </profile>
>>>
>>>                 <profile>
>>>                         <id>recreateTestDbOFF</id>
>>>                         <activation>
>>>                                 <property>
>>> <name>!recreateTestDb</name>
>>>                                 </property>
>>>                         </activation>
>>>                         ...
>>>                 </profile>
>>>
>>> And have your users enable the feature using:
>>>
>>>      mvn -DrecreateTestDb
>>>
>>> Regards,
>>> Curtis
>>>
>>>
>>> On Thu, Aug 8, 2013 at 4:13 PM, laredotornado-3 <laredotornado@gmail.com
>>> >**wrote:
>>>
>>>  Hi,
>>>>
>>>> I'm using Maven 3.0.3.  I want to activate a profile (profileA) at all
>>>> times
>>>> unless the user specifically requests profile B on the command line
>>>> (e.g.
>>>> "-P profileB").  However, right now both profiles are active when I run
>>>>
>>>>         mvn clean install -P profileB
>>>>
>>>> and I can't figure out why.  Here's the relevant section from my parent
>>>> pom.xml <profiles> section:
>>>>
>>>>                 <profile>
>>>>                         <id>profileB</id>
>>>>                         <properties>
>>>> <recreateTestDb>true</**recreateTestDb>
>>>>                         ...
>>>>                         </properties>
>>>>                 </profile>
>>>>
>>>>                 <profile>
>>>>                         <id>profileA</id>
>>>>                         <activation>
>>>>                                 <property>
>>>> <name>!recreateTestDb</name>
>>>>                                 </property>
>>>>                         </activation>
>>>>                         <properties>
>>>>                                ...
>>>>                         </properties>
>>>>                 </profile>
>>>>
>>>> Any suggestions how to configure the profiles to get the desired
>>>> behavior?
>>>> Thanks, - Dave
>>>>
>>>>
>>>>
>>>> --
>>>> View this message in context:
>>>> http://maven.40175.n5.nabble.**com/How-do-I-de-activate-a-**
>>>> profile-if-another-profile-is-**specified-tp5767107.html<http://maven.40175.n5.nabble.com/How-do-I-de-activate-a-profile-if-another-profile-is-specified-tp5767107.html>
>>>> Sent from the Maven - Users mailing list archive at Nabble.com.
>>>>
>>>> ------------------------------**------------------------------**
>>>> ---------
>>>> To unsubscribe, e-mail: users-unsubscribe@maven.**apache.org<users-unsubscribe@maven.apache.org>
>>>> For additional commands, e-mail: users-help@maven.apache.org
>>>>
>>>>
>> ------------------------------**------------------------------**---------
>> To unsubscribe, e-mail: users-unsubscribe@maven.**apache.org<users-unsubscribe@maven.apache.org>
>> For additional commands, e-mail: users-help@maven.apache.org
>>
>>  Besides the usual concrete implementation in maven syntax, you could
> actually do something like:
>
> mkdir profile(x)
> mv profile(x-1) profile(x)
> mkdir profile(x+1)            # profile(x+1) is in the top-level directory
>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@maven.**apache.org<users-unsubscribe@maven.apache.org>
> For additional commands, e-mail: users-help@maven.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message