Monday, March 21, 2016

Enforcing Semantic Versioning in your Maven project with japicmp

I'm a big fan of Semantic Versioning. Recently I have been working on breaking our monolithic web applications into smaller "plugins". The first step in such an endeavor is creating an API between the main application and your plugins. My concern in doing that was that it is very easy to break compatibility and roll out a change that crashes the app or causes some feature to crash. After all semantic versioning is just a convention. I needed a tool to enforce the convention. japicmp to the rescue!

Basically you configure the plugin to point to an artifact that represents your API level. It compares the binary compatibility between your project and that one to ensure you have not broken compatibility.

Here are a couple of quick tests I did to make sure this would do what I wanted. Keep in mind that the API version is 1.0.0 and my current project version is 1.0.0-SNAPSHOT unless otherwise specified.
  1. I added an argument to a method in a public interface. I expected it to break since this would certainly break compatibility. You should increase your MAJOR version number if you are going to do this.
  2. I increased my MAJOR version and retested #1. The build succeeded.
  3. I added a method to a public interface and it broke the build. I should increase my MINOR version if I'm going to make this change.
  4. I increased my MINOR version and retested #3. The build succeeded.
  5. I changed the internal implementation of a concrete class and the build succeeded.
At this point I was pretty convinced. I know there are many more scenarios to test but this is a good start and it seems pretty promising. Here's the plugin configuration I used in my pom file.

I should mention there are other alternatives out there. Although this one is the only one that passed my "sniff" test and my actual tests. I'll list the other ones I looked at here and why I didn't choose them. I think as Software Engineers it's always important for us to look at several options when possible and choose which one fits our needs best.

http://www.mojohaus.org/clirr-maven-plugin/
This one is really flexible but it's not set up specifically for Semantic Versioning. I wasn't able to configure it to pass my tests above but it might be possible.

https://github.com/jeluard/semantic-versioning
This one is really straight forward and is actually not a plugin itself. It is a couple of rules that can be configured in the maven enforcer plugin. I didn't test this one because at the top of the README it states that it is dormant and actually suggests we look at japicmp.

Here's the link to the maven documentation for japicmp. You should definitely check it out if you are wanting to enforce Semantic Versioning in your projects.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.