Is it possible to use maven buildnumber plugin to generate build number without any scm check?
Asked Answered
K

6

31

Getting the following exception while using maven build number plugin. Is it possible to disable SCM check while using the build number plugin? Can we use this plugin to generate build number on non SCM build?

Exception while doing the build:

[ERROR] Failed to execute goal org.codehaus.mojo:buildnumber-maven-plugin:1.0:create (default) on project projectname: Execution default of goal org.codehaus.mojo:buildnumber-maven-plugin:1.0:create failed: The scm url cannot be null. -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:buildnumber-maven-plugin:1.0:create (default) on project projectname: Execution default of goal org.codehaus.mojo:buildnumber-maven-plugin:1.0:create failed: The scm url cannot be null.
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:225)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:534)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default of goal org.codehaus.mojo:buildnumber-maven-plugin:1.0:create failed: The scm url cannot be null.
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:116)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
    ... 19 more
Caused by: java.lang.NullPointerException: The scm url cannot be null.
    at org.apache.maven.scm.manager.AbstractScmManager.makeScmRepository(AbstractScmManager.java:183)
    at org.codehaus.mojo.build.CreateMojo.getScmRepository(CreateMojo.java:768)
    at org.codehaus.mojo.build.CreateMojo.getRevision(CreateMojo.java:692)
    at org.codehaus.mojo.build.CreateMojo.execute(CreateMojo.java:443)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:107)
    ... 20 more

POM configuration:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>buildnumber-maven-plugin</artifactId>
    <version>1.0</version>
    <executions>
    <execution>
      <phase>validate</phase>
      <goals>
    <goal>create</goal>
    <goal>create-timestamp</goal>
      </goals>
    </execution>
    </executions>
    <configuration>
    <buildNumberPropertyName>build.number</buildNumberPropertyName>
    <timestampFormat>yyyy-MM-dd HH:mm:ss.SSS z</timestampFormat>
    <timestampPropertyName>build.time</timestampPropertyName>
    <doCheck>false</doCheck>
    <doUpdate>false</doUpdate>
    </configuration>
</plugin>

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.0.2</version>
    <configuration>
    <source>1.6</source>
    <target>1.6</target>
    </configuration>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.1.1</version>
    <configuration>
    <warname>foodwalaweb</warname>
    <!--webResources>
        <resource>
        <filtering>false</filtering>
        <directory>${basedir}/src/main/java</directory>
        <includes>
        <include>META-INF/persistence.xml</include>
        </includes>
        </resource>
    </webResources-->
    <archive>
    <manifest>
        <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
        <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
    </manifest>
    <manifestEntries>
        <Build-Number>${buildNumber}</Build-Number>
        <Built-Time>${build.time}</Built-Time>
    </manifestEntries>
    </archive>
    </configuration>
</plugin>
Koala answered 2/2, 2012 at 16:15 Comment(0)
C
31

Define a dummy SCM and then use buildNumber item to get sequential build number instead of value defined by revisionOnScmFailure property.

pom.xml:

<project ...>

    <scm>
        <connection>scm:svn:http://127.0.0.1/dummy</connection>
        <developerConnection>scm:svn:https://127.0.0.1/dummy</developerConnection>
        <tag>HEAD</tag>
        <url>http://127.0.0.1/dummy</url>
    </scm>

    <build>
      <plugins>

        ...

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>buildnumber-maven-plugin</artifactId>
            <version>1.1</version>
            <executions>
            <execution>
                <id>buildnumber</id>
                <phase>validate</phase>
                <goals>
                <goal>create</goal>
                </goals>
            </execution>
            </executions>
            <configuration>
                <format>{0,number}</format>
                <items>
                <item>buildNumber</item>
                </items>                    
                <doCheck>false</doCheck>
                <doUpdate>false</doUpdate>
                <revisionOnScmFailure>unknownbuild</revisionOnScmFailure>   
            </configuration>
        </plugin>


      </plugins>
    </build>
</project>
Caramelize answered 1/6, 2012 at 9:31 Comment(0)
K
11

With version 1.4 the following works:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>buildnumber-maven-plugin</artifactId>
    <version>1.4</version>
    <configuration>
        <revisionOnScmFailure>no.scm.config.in.pom</revisionOnScmFailure>
    </configuration>
    <executions>
        <execution>
            <id>create-timestamp-id</id>
            <phase>validate</phase>
            <goals>
                <goal>create-timestamp</goal>
            </goals>
            <configuration>
                <timestampFormat>yyyy-MM-dd HH:mm:ss.S</timestampFormat>
                <timestampPropertyName>myBuildNumberVariable</timestampPropertyName>
                <!-- formats the timestamp all together like 2016-04-04 14:17:05.123 and puts 
                    it in the ${myBuildNumberVariable} buildProperty -->
            </configuration>
        </execution>
    </executions>
</plugin>
Kuenlun answered 7/4, 2016 at 20:25 Comment(3)
Thanks! Finally I can get rid of that SCM dummy!Dyl
Hurrah. This works. Don't know why the information on the plugin site is not as clear as this.Wein
Looks like SCM is not required on the create-timestamp goal, as soon as you switch to create goal to get an actual int for the build number it fails.Anfractuous
L
4

All you need to do is to enclose your plugins within pluginManagement tag

<pluginManagement>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>buildnumber-maven-plugin</artifactId>
            <executions>
                <execution>
                    <phase>validate</phase>
                    <goals>
                        <goal>create</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <doCheck>true</doCheck>
                <doUpdate>true</doUpdate>
            </configuration>
        </plugin>
    </plugins>
</pluginManagement>
Landpoor answered 15/2, 2017 at 0:0 Comment(0)
I
0

The following used to work, if I'm not mistaken:

  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>buildnumber-maven-plugin</artifactId>
    <version>1.0-beta-3</version>
    <configuration>
      <buildNumberPropertyName>buildNumber.value</buildNumberPropertyName>
      <timestampPropertyName>buildNumber.timestamp</timestampPropertyName>
      <format>{0,date,yyyyMMdd-HHmm}</format>
      <items>
        <item>timestamp</item>
      </items>
    </configuration>
    <executions>
      <execution>
        <phase>validate</phase>
        <goals>
          <goal>create</goal>
        </goals>
      </execution>
    </executions>
  </plugin>
</plugins>
Isidraisidro answered 2/2, 2012 at 19:32 Comment(1)
I need to generate the build number and build time like the following format. The above code didn't help. It is printing the correct timestamp, If I use the code which I posted. But it is failing for build number. "Build-Number: x.x.x.1" "Built-Time: 2012-02-09 11:30:48.885 EST" Any body has any other thoughts or suggestions?Koala
S
0

I had the case, that I wanted a GIT commitId and a timestamp to be put into properties, both at the same time. Can this be done as well?
Of course:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>buildnumber-maven-plugin</artifactId>
    <version>1.4</version>
    <inherited>false</inherited>
    <executions>
        <execution>
            <id>commitId</id>
            <phase>validate</phase>
            <goals>
                <goal>create</goal>
            </goals>
            <configuration>
                <buildNumberPropertyName>commitId</buildNumberPropertyName>
                <shortRevisionLength>7</shortRevisionLength>
            </configuration>
        </execution>
        <execution>
            <id>buildTimestamp</id>
            <phase>validate</phase>
            <goals>
                <goal>create-timestamp</goal>
            </goals>
            <configuration>
                <timestampPropertyName>buildTimestamp</timestampPropertyName>
            </configuration>
        </execution>
    </executions>
</plugin>
Sigh answered 30/8, 2018 at 14:37 Comment(0)
S
-1

This work file for me. Might help with just version number and no need of scm.

<plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>buildnumber-maven-plugin</artifactId>
            <version>1.4</version>
            <configuration>
             <revisionOnScmFailure>no.scm.config.in.pom
                 </revisionOnScmFailure>
            </configuration>
            <executions>
                <execution>
                    <id>buildnumber</id>
                    <phase>validate</phase>
                    <goals>
                        <goal>create</goal>
                    </goals>
                    <configuration>
                        <format>{0,number}</format>
                        <items>
                            <item>buildNumber</item>
                        </items>
                        <doCheck>false</doCheck>
                        <doUpdate>false</doUpdate>
                        <revisionOnScmFailure>unknownbuild</revisionOnScmFailure>
                    </configuration>
                </execution>
            </executions>
        </plugin>
Schiff answered 19/5, 2017 at 5:33 Comment(1)
It is not working for me. I am sure that everything is the same. Do I need to have something more?Orientalism

© 2022 - 2024 — McMap. All rights reserved.