maven 自动编译版本号 buildnumber-maven-plugin 1.4

    最近新项目要需要更新发布版本号,用于标识发布的版本,网上找了下插件:buildnumber-maven-plugin 1.4 。

记录下自己使用成功过程中遇到的各种问题,以供需要的朋友参考:


    插件官方网站:http://www.mojohaus.org/buildnumber-maven-plugin/usage.html (官网内附详细说明)

        

    一、在项目pom.xml中添加相关配置

1).<plugins>...</plugins>中添加buildnumber-maven-plugin插件。

		      <!-- 自动更新版本号   -->
		      <plugin>
		        <groupId>org.codehaus.mojo</groupId>
		        <artifactId>buildnumber-maven-plugin</artifactId>
		        <version>1.4</version>
		        <configuration>
			  <format>{0,date,yyyy-MM-dd HH:mm:ss}</format>
			  <items>
			     <item>timestamp</item>
			  </items>
			</configuration>
		        <executions>
		          <execution>
		            <phase>validate</phase>
		            <goals>
		              <goal>create-timestamp</goal>
		            </goals>
		          </execution>
		        </executions>
		      </plugin>
	2).<build>...</build>中添加上面item:timestamp指定输出的配置文件的路径:
	我把timestamp输出的版本号(时间戳格式的)放在 monitor.properties里。
	
	  <directory>...</directory>里的内容为配置文件的目录路径:src/main/resources
	       
	       <resources>
	   <resource>
             <directory>src/main/resources</directory>
               <filtering>true</filtering>
           </resource>
      	 </resources>


   3).timestamp输出属性定义:

      与.properties文件中的相对应。

  	<properties>
    	  <project.build.timestamp>${timestamp}</project.build.timestamp>
  	</properties>
二、jave代码中读取monitor.properties文件中的project.build.timestamp属性,将时间戳格式转化成想要的日期格式,保存到库表。


-----------------------------------------------------------------------------------------------------------------------------------------------------------------

        遇到的问题:

1. 开始用的是<goal>create</goal>,但是编译会报错,替换成<goal>create-timestamp</goal>即可。

[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)

2. eclipse里excution报错:

解决办法:

参考http://blog.csdn.net/huweijun_2012/article/details/51073782

3. maven clean install 编译工程报错:

[ERROR] Failed to execute goal org.codehaus.mojo:buildnumber-maven-plugin:1.4:cr
eate-timestamp (default) on project gdws-svc: Execution default of goal org.code
haus.mojo:buildnumber-maven-plugin:1.4:create-timestamp failed: A required class
 was missing while executing org.codehaus.mojo:buildnumber-maven-plugin:1.4:crea
te-timestamp: org/apache/commons/lang/StringUtils
[ERROR] -----------------------------------------------------
[ERROR] realm =    plugin>org.codehaus.mojo:buildnumber-maven-plugin:1.4
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/D:/IDEStrain/maven/repository/org/codehaus/mojo/buildnum
ber-maven-plugin/1.4/buildnumber-maven-plugin-1.4.jar
[ERROR] urls[1] = file:/D:/IDEStrain/maven/repository/backport-util-concurrent/b
ackport-util-concurrent/3.1/backport-util-concurrent-3.1.jar
[ERROR] urls[2] = file:/D:/IDEStrain/maven/repository/org/codehaus/plexus/plexus
-interpolation/1.11/plexus-interpolation-1.11.jar
[ERROR] urls[3] = file:/D:/IDEStrain/maven/repository/org/slf4j/slf4j-jdk14/1.5.
6/slf4j-jdk14-1.5.6.jar
[ERROR] urls[4] = file:/D:/IDEStrain/maven/repository/org/slf4j/slf4j-api/1.5.6/
slf4j-api-1.5.6.jar
[ERROR] urls[5] = file:/D:/IDEStrain/maven/repository/org/slf4j/jcl-over-slf4j/1
.5.6/jcl-over-slf4j-1.5.6.jar
[ERROR] urls[6] = file:/D:/IDEStrain/maven/repository/org/apache/maven/reporting
/maven-reporting-api/2.2.1/maven-reporting-api-2.2.1.jar
[ERROR] urls[7] = file:/D:/IDEStrain/maven/repository/org/apache/maven/doxia/dox
ia-sink-api/1.1/doxia-sink-api-1.1.jar
[ERROR] urls[8] = file:/D:/IDEStrain/maven/repository/org/apache/maven/doxia/dox
ia-logging-api/1.1/doxia-logging-api-1.1.jar
解决:

执行buildnumber-maven-plugin插件时找不到commons-lang的StringUtils类。通过查看 maven本地仓库buildnumber-maven-plugin-1.4.pom文件,发现没有配置commons-lang包的依赖,添加配置如下依赖:

<dependency>
<groupId>commons-lang</groupId>
       <artifactId>commons-lang</artifactId>
       <version>2.3</version>
</dependency>
重新执行 clean install 通过!









  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值