[ 
https://jira.codehaus.org/browse/MNG-5490?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=339901#comment-339901
 ] 

Gregory Baumgardner commented on MNG-5490:
------------------------------------------

Ok, let me break it down simply.  You can do write two separate profiles with 
two separate executions to do a common task that is to be done for both clean 
and default lifecycles.  In my case, I am running an Ant script to run some 
pre-script and set properties.  One execution of the antrun plugin is bound to 
initialize phase, and the other is in pre-clean.  This works fine, but it would 
be so much nicer to only define one single profile with one single execution 
that is bound to a variable phase controlled by a property, like ${init-phase} 
shown above.  I have this working, but you must set the init-phase property 
differently, depending on whether the lifecycle is clean or the default.  This 
is, as far as I can tell, impossible in the POM.  So, it would be cool to have 
an <activation> option to specify the lifecycle, in order to define two extra 
profiles whose purpose is to set the property.  
                
> Add support for "lifecycle" activation for profiles
> ---------------------------------------------------
>
>                 Key: MNG-5490
>                 URL: https://jira.codehaus.org/browse/MNG-5490
>             Project: Maven 2 & 3
>          Issue Type: Improvement
>          Components: Profiles
>    Affects Versions: 2.2.1
>         Environment: Windows 7
>            Reporter: Gregory Baumgardner
>            Priority: Minor
>
> I have the following scenario: Initialization step is done in the default 
> lifecycle "initialize" phase which sets properties that are used in later 
> build phases.  Unfortunately, the same properties need set in the "clean" 
> lifecycle in order to use them in the clean phase.  There is no way to easily 
> run the same execution of plugins without duplication.  However, it turns out 
> very easy to manipulate the phase attribute in the following way:
> <profile>
>   <id>default-phase</id>
>   <activation>
>     <property>
>       <name>!clean-all</name>
>     </property>
>   </activation>
>   <properties>
>     <init-phase>initialize</init-phase>
>   </properties>
> </profile>
> <profile>
>   <id>clean-phase</id>
>   <activation>
>     <property>
>       <name>clean-all</name>
>     </property>
>   </activation>
>   <properties>
>     <init-phase>pre-clean</init-phase>
>   </properties>
> </profile>
> <profile>
>   <id>plugin-config</id>
>   <activation>
>     <property>
>       <name>java.version</name> <!-- Always on -->
>     </property>
>   </activation>
>   <build>
>     <plugins>
>       <plugin>
>    ... <!-- Whatever plugin -->
>          <executions>
>            <execution>
>              <id>initialize properties</id>
>              <goals><goal><!--The goal --></goal></goals>
>              <phase>${init-phase}</phase>
>              <configuration>
>                <!-- The plugin config to use -->
>              </configuration>
>            </execution>
>          </executions>
>        </plugin>
>       ...
>     </plugins>
>   </build>
> </profile>
> This will run the initialize step under initialize phase for default 
> lifecycle and under pre-clean phase for clean lifecycle provided that the 
> config information falls after the property set in a profile.  However, the 
> one issue I have with this is that it requires you to run Maven with 
> -Dclean-all property on the command line.  It would be even better if there 
> was an activation for <lifecycle> that could be set to "default", "clean", 
> "site", etc.  Then, the activation can occur when that specific lifecycle is 
> invoked during the build.  As far as I can tell, there is no other way to 
> determine this information.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to