You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Enrique Gaona <eg...@us.ibm.com> on 2007/02/24 00:25:36 UTC

[M2]maven-buildnumber-plugin


How do you run a plugin the parent pom only once and have its configuration
inherited by its children.   I'm using the maven-buildnumber-plugin in my
parent pom and when I run my build, this plugin gets executed on every
child pom and I end up with different buildNumber ID.

            <plugin>
                                <groupId>org.codehaus.mojo</groupId>

<artifactId>maven-buildnumber-plugin</artifactId>
                                <version>0.9.4</version>
                                <executions>
                                        <execution>
                                                <phase>validate</phase>
                                                <goals>
                                                        <goal>create</goal>
                                                </goals>
                                        </execution>
                                </executions>
                                <configuration>
                                        <doCheck>false</doCheck>
                                        <doUpdate>false</doUpdate>
                                        <format>{0,date,yyyy-MM-dd
HH:mm:ss}</format>
                                        <items>
                                                <item>timestamp</item>
                                        </items>
                                </configuration>
                        </plugin>


As you can see from the output, the both the parent and child pom.xml
executes the plugin ad the  buildNumber gets changed.   So, basically, I
just want the plugin to run once and have the child poms inherit the
buildNumber.   Is this doable?  I tried using the
<inherited>false</inherited> in the parent pom, it executes the plugin
once, but the child poms do not get the buildNumber.


[INFO]
----------------------------------------------------------------------------
[INFO] Building Master POM File csdp.platform version 1.1 (csdp_dev latest)
[INFO]    task-segment: [clean, antrun:run, install, rpm:rpm]
[INFO]
----------------------------------------------------------------------------
[INFO] [clean:clean]
[INFO] Deleting directory
/home/egaona/projects/csdp_build/sources/csdp/target
[INFO] Deleting directory
/home/egaona/projects/csdp_build/sources/csdp/target/classes
[INFO] Deleting directory
/home/egaona/projects/csdp_build/sources/csdp/target/test-classes
[INFO] [antrun:run]
[INFO] Executing tasks
[INFO] Executed tasks
[INFO] [buildnumber:create {execution: default}]
[INFO] Storing buildNumber: 2007-02-23 17:07:06   <----****************


[INFO]
----------------------------------------------------------------------------
[INFO] Building CSDP Prereq Main
[INFO]    task-segment: [clean, antrun:run, install, rpm:rpm]
[INFO]
----------------------------------------------------------------------------
[INFO] [clean:clean]
[INFO] Deleting directory
/home/egaona/projects/csdp_build/sources/csdp/com.ibm.csdp.prereq/target
[INFO] Deleting directory
/home/egaona/projects/csdp_build/sources/csdp/com.ibm.csdp.prereq/target/classes
[INFO] Deleting directory
/home/egaona/projects/csdp_build/sources/csdp/com.ibm.csdp.prereq/target/test-classes
[INFO] [antrun:run]
[INFO] Executing tasks
[INFO] Executed tasks
[INFO] [buildnumber:create {execution: default}]
[INFO] Storing buildNumber: 2007-02-23 17:07:09
<----******************


Enrique

Re: [m2] maven-buildnumber-plugin

Posted by Enrique Gaona <eg...@us.ibm.com>.
I'm not sure if the aggregator works if you're using a timestamp as the
build number, it certainly didn't for me.  This is what I have in my
BuildNumberMojo.java or perhaps I'm passing the wrong options:-)

 * @author <a href="mailto:woodj@ucalgary.ca">Julian Wood</a>
 * @version $Id: BuildNumberMojo.java,v 1.1 2007/02/26 20:52:42 egaona Exp
$
 * @goal create
 * @requiresProject
 * @description create a build number from scm if possible, otherwise a
timestamp
 * @aggregator true
 * @requiresOnline true
 * @inheritedByDefault false



Enrique



fgarsombke <fg...@yahoo.com> wrote on 02/28/2007 03:12:19 PM:

>
> I got around this by making the build-number-plugin @aggregator style.
>
> I just changed the javadoc tag in the plugin and rebuilt it.
>
>
> /**
>  * This mojo is designed to give you a build number. So when you might
make
> 100 builds of version
>  * 1.0-SNAPSHOT, you can differentiate between them all. The build number
is
> based on the revision
>  * number retrieved from scm. It only works with subversion, currently.
This
> mojo can also check to make
>  * sure that you have checked everything into scm, before issuing the
build
> number. That behaviour can be suppressed,
>  * and then the latest local build number is used. Build numbers are not
> reflected
>  * in your artifact's filename (automatically), but can be added to the
> metadata. You can access the build
>  * number in your pom with ${buildNumber}.
>  *
>  * @author  mailto:woodj@ucalgary.ca Julian Wood
>  * @version $Id: BuildNumberMojo.java,v 1.0 Feb 7, 2006 11:43:08 AM woodj
> Exp $
>  * @goal create
>  * @requiresProject
>  * @aggregator
>  * @description create a build number from scm if possible, otherwise a
> timestamp
>  */
>
> It then only increments the build number once per the entire build.
>
>
> Franz Garsombke
> --
> View this message in context: http://www.nabble.com/maven-
> buildnumber-plugin-tf3281875s177.html#a9235485
> Sent from the Maven - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>

Re: [m2] maven-buildnumber-plugin

Posted by Franz Garsombke <fg...@yahoo.com>.
I wouldn't think anyone is using it 'per' module. I did open a feature
request in the Maven Jira for the ability to dynamically change the behavior
of all maven plugins from per module to aggregator. This might help these
kind of issues in the future. Thanks for writing the plugin :)

Franz


Julian Wood wrote:
> 
> This is a nice solution. I wonder if there's any way to trigger this  
> behaviour on demand. Or maybe I should just change the plugin to  
> always be an aggregator. I wonder if anyone depends on it running  
> once per module?
> 
> J
> 
> On 28-Feb-07, at 2:12 PM, fgarsombke wrote:
> 
>>
>> I got around this by making the build-number-plugin @aggregator style.
>>
>> I just changed the javadoc tag in the plugin and rebuilt it.
>>
>>
>> /**
>>  * This mojo is designed to give you a build number. So when you  
>> might make
>> 100 builds of version
>>  * 1.0-SNAPSHOT, you can differentiate between them all. The build  
>> number is
>> based on the revision
>>  * number retrieved from scm. It only works with subversion,  
>> currently. This
>> mojo can also check to make
>>  * sure that you have checked everything into scm, before issuing  
>> the build
>> number. That behaviour can be suppressed,
>>  * and then the latest local build number is used. Build numbers  
>> are not
>> reflected
>>  * in your artifact's filename (automatically), but can be added to  
>> the
>> metadata. You can access the build
>>  * number in your pom with ${buildNumber}.
>>  *
>>  * @author  mailto:woodj@ucalgary.ca Julian Wood
>>  * @version $Id: BuildNumberMojo.java,v 1.0 Feb 7, 2006 11:43:08 AM  
>> woodj
>> Exp $
>>  * @goal create
>>  * @requiresProject
>>  * @aggregator
>>  * @description create a build number from scm if possible,  
>> otherwise a
>> timestamp
>>  */
>>
>> It then only increments the build number once per the entire build.
>>
>>
>> Franz Garsombke
>> -- 
> 
> --
> Julian Wood <wo...@ucalgary.ca>
> 
> Software Engineer
> Teaching & Learning Centre
> University of Calgary
> 
> http://tlc.ucalgary.ca
> 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/maven-buildnumber-plugin-tf3281875s177.html#a9241889
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: [m2] maven-buildnumber-plugin

Posted by Julian Wood <wo...@ucalgary.ca>.
This is a nice solution. I wonder if there's any way to trigger this  
behaviour on demand. Or maybe I should just change the plugin to  
always be an aggregator. I wonder if anyone depends on it running  
once per module?

J

On 28-Feb-07, at 2:12 PM, fgarsombke wrote:

>
> I got around this by making the build-number-plugin @aggregator style.
>
> I just changed the javadoc tag in the plugin and rebuilt it.
>
>
> /**
>  * This mojo is designed to give you a build number. So when you  
> might make
> 100 builds of version
>  * 1.0-SNAPSHOT, you can differentiate between them all. The build  
> number is
> based on the revision
>  * number retrieved from scm. It only works with subversion,  
> currently. This
> mojo can also check to make
>  * sure that you have checked everything into scm, before issuing  
> the build
> number. That behaviour can be suppressed,
>  * and then the latest local build number is used. Build numbers  
> are not
> reflected
>  * in your artifact's filename (automatically), but can be added to  
> the
> metadata. You can access the build
>  * number in your pom with ${buildNumber}.
>  *
>  * @author  mailto:woodj@ucalgary.ca Julian Wood
>  * @version $Id: BuildNumberMojo.java,v 1.0 Feb 7, 2006 11:43:08 AM  
> woodj
> Exp $
>  * @goal create
>  * @requiresProject
>  * @aggregator
>  * @description create a build number from scm if possible,  
> otherwise a
> timestamp
>  */
>
> It then only increments the build number once per the entire build.
>
>
> Franz Garsombke
> -- 

--
Julian Wood <wo...@ucalgary.ca>

Software Engineer
Teaching & Learning Centre
University of Calgary

http://tlc.ucalgary.ca



Re: [m2] maven-buildnumber-plugin

Posted by fgarsombke <fg...@yahoo.com>.
I got around this by making the build-number-plugin @aggregator style.

I just changed the javadoc tag in the plugin and rebuilt it.


/**
 * This mojo is designed to give you a build number. So when you might make
100 builds of version
 * 1.0-SNAPSHOT, you can differentiate between them all. The build number is
based on the revision
 * number retrieved from scm. It only works with subversion, currently. This
mojo can also check to make
 * sure that you have checked everything into scm, before issuing the build
number. That behaviour can be suppressed,
 * and then the latest local build number is used. Build numbers are not
reflected
 * in your artifact's filename (automatically), but can be added to the
metadata. You can access the build
 * number in your pom with ${buildNumber}.
 *
 * @author  mailto:woodj@ucalgary.ca Julian Wood 
 * @version $Id: BuildNumberMojo.java,v 1.0 Feb 7, 2006 11:43:08 AM woodj
Exp $
 * @goal create
 * @requiresProject
 * @aggregator
 * @description create a build number from scm if possible, otherwise a
timestamp
 */

It then only increments the build number once per the entire build.


Franz Garsombke
-- 
View this message in context: http://www.nabble.com/maven-buildnumber-plugin-tf3281875s177.html#a9235485
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: [M2]maven-buildnumber-plugin

Posted by Enrique Gaona <eg...@us.ibm.com>.
Julian Wood <wo...@ucalgary.ca> wrote on 02/28/2007 12:27:37 PM:

> I don't know how you can do this. I've come across this before, and
> haven't been able to come up with a solution. In the end, you have to
> work with it. Either change the format so that it is something which
> will be the same even if they are executed a few seconds apart, or
> use revision numbers from scm, which will be the same.
Yeah, this would have been my choice, but the developers want a date
timestamp:-)
>
> If anyone knows how to prevent the modules from running the parent
> plugin, please let us know. Actually, I wonder if you could specify
> the plugin in the module poms again, but fiddle with the execution.
> Does it override what the parent specifies? Does it execute in
> addition to the parent? If it overrides, then you could change the
> phase or get rid of the goal. You might be able to stop it that way.
> Worth a shot.
In the end, my workaround was to modify the maven-buildnumber-plugin.
Here's the code snippet

 if ( project != null )
 {
            //Check if buildNumber has been set
            //If not, set it to t buildNumber
            String buildnum = System.getProperty("buildNumber");
            if (buildnum == null)
            {
                System.setProperty("buildNumber", revision);
            }

            revision = System.getProperty("buildNumber");
            project.getProperties().put( "buildNumber", revision );
            String buildnumber = (String)
project.getProperties().get("buildNumber");
            getLog().info( "Build Number: " + buildnumber );
 }

Enrique

>
> J
>
> On 24-Feb-07, at 12:19 PM, Enrique Gaona wrote:
>
> > Hi,
> > Anyone know how I can do this? Thanks
> >
> > Enrique
> >
> >> How do you run a plugin the parent pom only once and have its
> >> configuration
> >> inherited by its children.   I'm using the maven-buildnumber-
> >> plugin in my
> >> parent pom and when I run my build, this plugin gets executed on
> >> every
> >> child pom and I end up with different buildNumber ID.
> >
> >            <plugin>
> >                                <groupId>org.codehaus.mojo</groupId>
> >
> > <artifactId>maven-buildnumber-plugin</artifactId>
> >                                <version>0.9.4</version>
> >                                <executions>
> >                                        <execution>
> >                                                <phase>validate</phase>
> >                                                <goals>
> >
> > <goal>create</goal>
> >                                                </goals>
> >                                        </execution>
> >                                </executions>
> >                                <configuration>
> >                                        <doCheck>false</doCheck>
> >                                        <doUpdate>false</doUpdate>
> >                                        <format>{0,date,yyyy-MM-dd
> > HH:mm:ss}</format>
> >                                        <items>
> >                                                <item>timestamp</item>
> >                                        </items>
> >                                </configuration>
> >                        </plugin>
> >
> >
> > As you can see from the output, the both the parent and child pom.xml
> > executes the plugin ad the  buildNumber gets changed.   So,
> > basically, I
> > just want the plugin to run once and have the child poms inherit the
> > buildNumber.   Is this doable?  I tried using the
> > <inherited>false</inherited> in the parent pom, it executes the plugin
> > once, but the child poms do not get the buildNumber.
> >
>
> --
> Julian Wood <wo...@ucalgary.ca>
>
> Software Engineer
> Teaching & Learning Centre
> University of Calgary
>
> http://tlc.ucalgary.ca
>
>

Re: [M2]maven-buildnumber-plugin

Posted by Julian Wood <wo...@ucalgary.ca>.
I don't know how you can do this. I've come across this before, and  
haven't been able to come up with a solution. In the end, you have to  
work with it. Either change the format so that it is something which  
will be the same even if they are executed a few seconds apart, or  
use revision numbers from scm, which will be the same.

If anyone knows how to prevent the modules from running the parent  
plugin, please let us know. Actually, I wonder if you could specify  
the plugin in the module poms again, but fiddle with the execution.  
Does it override what the parent specifies? Does it execute in  
addition to the parent? If it overrides, then you could change the  
phase or get rid of the goal. You might be able to stop it that way.  
Worth a shot.

J

On 24-Feb-07, at 12:19 PM, Enrique Gaona wrote:

> Hi,
> Anyone know how I can do this? Thanks
>
> Enrique
>
>> How do you run a plugin the parent pom only once and have its  
>> configuration
>> inherited by its children.   I'm using the maven-buildnumber- 
>> plugin in my
>> parent pom and when I run my build, this plugin gets executed on  
>> every
>> child pom and I end up with different buildNumber ID.
>
>            <plugin>
>                                <groupId>org.codehaus.mojo</groupId>
>
> <artifactId>maven-buildnumber-plugin</artifactId>
>                                <version>0.9.4</version>
>                                <executions>
>                                        <execution>
>                                                <phase>validate</phase>
>                                                <goals>
>                                                         
> <goal>create</goal>
>                                                </goals>
>                                        </execution>
>                                </executions>
>                                <configuration>
>                                        <doCheck>false</doCheck>
>                                        <doUpdate>false</doUpdate>
>                                        <format>{0,date,yyyy-MM-dd
> HH:mm:ss}</format>
>                                        <items>
>                                                <item>timestamp</item>
>                                        </items>
>                                </configuration>
>                        </plugin>
>
>
> As you can see from the output, the both the parent and child pom.xml
> executes the plugin ad the  buildNumber gets changed.   So,  
> basically, I
> just want the plugin to run once and have the child poms inherit the
> buildNumber.   Is this doable?  I tried using the
> <inherited>false</inherited> in the parent pom, it executes the plugin
> once, but the child poms do not get the buildNumber.
>

--
Julian Wood <wo...@ucalgary.ca>

Software Engineer
Teaching & Learning Centre
University of Calgary

http://tlc.ucalgary.ca



Re: [M2]maven-buildnumber-plugin

Posted by Enrique Gaona <eg...@us.ibm.com>.
Hi,
Anyone know how I can do this?  Thanks

Enrique




                                                                           
             Enrique                                                       
             Gaona/Austin/IBM@                                             
             IBMUS                                                      To 
                                       "Maven Users List"                  
             02/23/2007 05:25          <us...@maven.apache.org>            
             PM                                                         cc 
                                                                           
                                                                   Subject 
             Please respond to         [M2]maven-buildnumber-plugin        
               "Maven Users                                                
                   List"                                                   
             <users@maven.apac                                             
                  he.org>                                                  
                                                                           
                                                                           






How do you run a plugin the parent pom only once and have its configuration
inherited by its children.   I'm using the maven-buildnumber-plugin in my
parent pom and when I run my build, this plugin gets executed on every
child pom and I end up with different buildNumber ID.

            <plugin>
                                <groupId>org.codehaus.mojo</groupId>

<artifactId>maven-buildnumber-plugin</artifactId>
                                <version>0.9.4</version>
                                <executions>
                                        <execution>
                                                <phase>validate</phase>
                                                <goals>
                                                        <goal>create</goal>
                                                </goals>
                                        </execution>
                                </executions>
                                <configuration>
                                        <doCheck>false</doCheck>
                                        <doUpdate>false</doUpdate>
                                        <format>{0,date,yyyy-MM-dd
HH:mm:ss}</format>
                                        <items>
                                                <item>timestamp</item>
                                        </items>
                                </configuration>
                        </plugin>


As you can see from the output, the both the parent and child pom.xml
executes the plugin ad the  buildNumber gets changed.   So, basically, I
just want the plugin to run once and have the child poms inherit the
buildNumber.   Is this doable?  I tried using the
<inherited>false</inherited> in the parent pom, it executes the plugin
once, but the child poms do not get the buildNumber.


[INFO]
----------------------------------------------------------------------------

[INFO] Building Master POM File csdp.platform version 1.1 (csdp_dev latest)
[INFO]    task-segment: [clean, antrun:run, install, rpm:rpm]
[INFO]
----------------------------------------------------------------------------

[INFO] [clean:clean]
[INFO] Deleting directory
/home/egaona/projects/csdp_build/sources/csdp/target
[INFO] Deleting directory
/home/egaona/projects/csdp_build/sources/csdp/target/classes
[INFO] Deleting directory
/home/egaona/projects/csdp_build/sources/csdp/target/test-classes
[INFO] [antrun:run]
[INFO] Executing tasks
[INFO] Executed tasks
[INFO] [buildnumber:create {execution: default}]
[INFO] Storing buildNumber: 2007-02-23 17:07:06   <----****************


[INFO]
----------------------------------------------------------------------------

[INFO] Building CSDP Prereq Main
[INFO]    task-segment: [clean, antrun:run, install, rpm:rpm]
[INFO]
----------------------------------------------------------------------------

[INFO] [clean:clean]
[INFO] Deleting directory
/home/egaona/projects/csdp_build/sources/csdp/com.ibm.csdp.prereq/target
[INFO] Deleting directory
/home/egaona/projects/csdp_build/sources/csdp/com.ibm.csdp.prereq/target/classes

[INFO] Deleting directory
/home/egaona/projects/csdp_build/sources/csdp/com.ibm.csdp.prereq/target/test-classes

[INFO] [antrun:run]
[INFO] Executing tasks
[INFO] Executed tasks
[INFO] [buildnumber:create {execution: default}]
[INFO] Storing buildNumber: 2007-02-23 17:07:09
<----******************


Enrique