简体   繁体   English

buildnumber-maven-plugin如何工作?

[英]How does buildnumber-maven-plugin work?

I have the below configuration to create a build number and save it in the MANIFEST.MF. 我具有以下配置来创建内部版本号并将其保存在MANIFEST.MF中。 The build process generates a buildNumber.properties and keeps track of the last build from it. 生成过程将生成一个buildNumber.properties,并从中跟踪上一次生成。 However this file I assume should be committed back into GIT as a part of storing the buildNumber. 但是,我认为应该将此文件提交回GIT,作为存储buildNumber的一部分。 Is this understanding correct? 这种理解正确吗? or is there any other way to achieve this? 还是有其他方法可以做到这一点?

build goal 建立目标

mvn clean package

pom.xml pom.xml

<scm>
<connection>scm:git:https://abc.xyz.com/#projects/scm/DOCKER-AbcServer.git</connection>
</scm>

<plugins>
  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>buildnumber-maven-plugin</artifactId>
    <version>1.4</version>
    <executions>
      <execution>
        <phase>validate</phase>
        <goals>
          <goal>create</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
      <format>{0,number}</format>
      <items>
        <item>buildNumber0</item>
      </items>
      <doCheck>true</doCheck>
      <doUpdate>true</doUpdate>
    </configuration>
  </plugin>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>3.1.0</version>
    <configuration>
      <archive>
        <manifest>
          <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
        </manifest>
        <manifestEntries>
          <Build-Number>${project.version}-r${buildNumber}</Build-Number>
          <Build-SCMBranch>${scmBranch}</Build-SCMBranch>
          <Build-Time>${maven.build.timestamp}</Build-Time>
        </manifestEntries>
      </archive>
    </configuration>
  </plugin>
</plugins>

buildNumber.properties buildNumber.properties

#maven.buildNumber.plugin properties file
#Fri Aug 10 10:49:49 PDT 2018
buildNumber0=2

If you commit your buildNumber.properties file you would get a build number that increments between each developer and continuous-integration builde EXCEPT if you build in your checkout and someone else does their build. 如果你提交你的buildNumber.properties文件,你会得到每个开发和持续集成builde如果你建立你的检验和别人做他们的构建EXCEPT之间增加一个版本号。 You'll both increment the build number. 你们都将增加内部版本号。 When one of you commits the file and pushes, which one of you wins? 当你们中的一个提交文件并推送时,你们中的哪个获胜? What is the current build number for the project? 该项目当前的内部版本号是多少?

I think it is more accurate to think of an incremental build number as "a build number for a particular clone" rather than one that is constant across the whole project. 我认为将增量内部版本号视为“特定克隆的内部版本号”比在整个项目中保持不变的版本号更为准确。

If you use git or svn or any other SCM that buildnumber is integrated with, you can use the SCM commit id as a build number instead of an integer. 如果您使用git或svn或与buildnumber集成的任何其他SCM,则可以使用SCM提交ID作为内部版本号,而不是整数。 This is inherently stored by the SCM and shows exactly what commit a build was made from. 它由SCM固有地存储,并准确显示了构建的提交内容。 I prefer this because by looking at a manifest file or JAR name I can immediately jump to the right commit to triage an issue or determine if a user is using an outdated build. 我更喜欢这样做,因为通过查看清单文件或JAR名称,我可以立即跳转到正确的提交以对问题进行分类或确定用户是否正在使用过时的版本。

Another good question covers some details of the buildnumber plugin and provides additional resources: Maven build number plugin, how to save the build number in a file? 另一个好的问题涵盖了buildnumber插件的一些细节,并提供了其他资源: Maven内部版本号插件,如何将内部版本号保存在文件中?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM