最近新项目要需要更新发布版本号,用于标识发布的版本,网上找了下插件:buildnumber-maven-plugin 1.4 。
记录下自己使用成功过程中遇到的各种问题,以供需要的朋友参考:
插件官方网站:http://www.mojohaus.org/buildnumber-maven-plugin/usage.html(官网内附详细说明)
一、在项目pom.xml中添加相关配置
1)....中添加buildnumber-maven-plugin插件。
org.codehaus.mojo
buildnumber-maven-plugin
1.4
{0,date,yyyy-MM-dd HH:mm:ss}
timestamp
validate
create-timestamp
2)....中添加上面item:timestamp指定输出的配置文件的路径:
我把timestamp输出的版本号(时间戳格式的)放在 monitor.properties里。
...里的内容为配置文件的目录路径:src/main/resources
src/main/resources
true
3).timestamp输出属性定义:
与.properties文件中的相对应。
${timestamp}
二、jave代码中读取
monitor.properties文件中的project.build.timestamp属性,将时间戳格式转化成想要的日期格式,保存到库表。
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
遇到的问题:
1. 开始用的是create,但是编译会报错,替换成create-timestamp即可。
[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包的依赖,添加配置如下依赖:
commons-lang
commons-lang
2.3
重新执行 clean install 通过!