Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven Plugin for project semantic versioning

I'm looking for a maven plugin that will help me manage version names and codes of every build that is made on our CI environment. Something that will be able to attach a prefix to the main version code or even update it (not changing the pom.xml). For example:

project version: 2.0.1
git/svn revision: 2342334

jar output: name-2.0.1-2342334.jar
maven repo: ../path/to/local/maven/repo/<package path>/2.0.1-2342334/

The main requirements to this plugin are:

  • Must be in Maven Repository (which means that NO additional setting required to add this plugin in my pom.xml and run maven)
  • Must not edit the pom, each time it's applied
  • A configuration file, would be great, so I could manage the versioning process
  • Must be able to edit the output file metadata (so the version will be applied as if it was written in the pom.xml file in the first place)

So far I found only maven-buildmetadata-pluging but unfortunately it's not in Maven Repo, so I'm stuck. Any help would be great.

like image 742
Serj Lotutovici Avatar asked Oct 02 '22 01:10

Serj Lotutovici


2 Answers

If you change the version of your artifact the pom has to reflect the change, cause otherwise it's not reproducible.

If you change something in your build process (like added versions, whatever) it has to be reflected in the pom file. Otherwise you can not reproduce the build process with the same result.

You have written not to change the pom file but maintaining a separate file. So the questions is: Why not using the pom file itself, cause it's intended exactly for that purpose.

Furthermore all informations which you mentioned by the maven-buildmetadata-plugin can be achived by using existing maven plugins (like build-helper-maven-plugin, buildnumber-maven-plugin).

The SCM information can be used by using the buildnumber-maven-plugin which provides information like SCM revision number (SVN or GIT hash).

An on the other hand if you don't like to change your pom file manually you can use either the versions-maven-plugin or the maven-release-plugin which automatically can change informations in your pom file and handle all these things automatically.

To maintain metadata in your producted artifacts you can configure all plugins (like ear, war, jar) etc. more or less like this where the buildNumber is comming from buildnumber-maven-plugin:

    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-jar-plugin</artifactId>
      <version>${maven-jar-plugin.version}</version>
      <configuration>
        <archive>
          <addMavenDescriptor>true</addMavenDescriptor>
          <index>true</index>
          <manifest>
            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
            <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
          </manifest>
          <manifestEntries>
            <artifactId>${project.artifactId}</artifactId>
            <groupId>${project.groupId}</groupId>
            <version>${project.version}</version>
            <buildNumber>${buildNumber}</buildNumber>
          </manifestEntries>
        </archive>
      </configuration>
    </plugin>

And of course if you really like to use Maven you should have to use an repository manager as already mentioned like Artifactory or Nexus which make life easier.

like image 82
khmarbaise Avatar answered Oct 13 '22 10:10

khmarbaise


Hosting your own maven repository is very easy, using either Nexus or Artifactory. You can also use the Artifactory cloud version (I'm not affiliated with them...) so it may solve your problem. BTW - a simple server with Apache does the trick as well, but with more work..,

Regarding the plugins: If you deploy snapshot applications then each gets its own version based on timestamp.

For releases another option is to run an svn info and put the result (or part of it) into the generated artifact. The information can then be accessed by the code.

like image 44
David Rabinowitz Avatar answered Oct 13 '22 11:10

David Rabinowitz