Maven extension(s) to facilitate continuous delivery of microservices
Continuously delivering microservices built by Maven is tough and painful.
-
Technology radar October 2012 - Thoughtworks
Maven has long been a staple of build automation in the Java space. However, given its lack of flexibility and support for automation best practices, especially in the Continuous Delivery domain, the use of alternatives such as Gradle should be considered.
Programming in the CI/CD tool is hard to scale.
-
Technology radar January 2015 Preview - Thoughtworks
A common pre-requisite for doing continuous integration has been to have a single command that could be executed on a clone of your repository on a brand new machine to get a working environment which can build, test and package your application. This focuses the attention on automation, makes it easy for new users to get started, reduces chances of snowflake build environments and results in reliable build results that can be recreated on demand either in the CI environment or locally. However, we often see teams ignoring this and resorting to programming in their CI/CD tool, which not only results in build failures that are hard to debug, they also lose out on the upstream benefits of having the single point of entry to configuring and building their projects. In this version of the radar, we would like to strongly advise against this practice which sacrifices many of the benefits of CI in the interest of expediency.
- Continuous delivery friendly Maven versions (MNG-5576) -> Fixed - Jason van Zyl
- Real-world strategies for continuous delivery with Maven and Jenkins - John Ferguson Smart
- Takari generations - Jason van Zyl
- Continuous Delivery for Microservices with Jenkins and the Job DSL Plugin
-
Requirements gathering
- Dave Dev says:
- Let me use my snapshots and for the rest stay out of my way ...
- Oliver Ops says:
- Freeze! And no adding a revision number in a manifest file is not good enough ...
- Jerry Jenkins
- I'll do it for you but Keep It Simple Stupid ...
- ...
- Dave Dev says:
-
Scope
- Java/JVM 1.7
- Maven as build tool
- Tested with 3.2.3
- git, svn as versioning tool
- Trunk based development using feature toggles
- ...
-
Solution
![Solution](/mvn-ext-freeze/src/doc/Continuous delivery with Maven.png?raw=true)
-
Bundle of Maven extensions
- General design rules for Maven extensions
- Maximal cohesion, minimal coupling
- Less is more
- Minimize the transitive jar dependencies of the extension
- Minimize the inter extension dependencies
- Follow or extrapolate existing Maven conventions/principles
- Piggyback existing Maven functionality
- Not viral
- Local preprocessing of poms
- Pom's stored in a Maven repository are processed poms and do not enforce installation of the extension when depending on these
- Graceful degradation when extension is not installed
- Does not break the Maven support in the IDE
- General design rules for Maven extensions
-
Algorithm
- Activate freezing when a revision is provided (-Drevision=xyz)
- Start parsing pom.xml file and stream it to frozen.pom.xml
- Extract the properties (groupId, artifactId, version) of the pom's project artifact
- Replace the snapshot ending of the pom's project artifact version with the given revision number (1.2-SNAPSHOT -> 1.2-xyz)
- For each snapshot dependency version encountered while parsing the pom
- Lookup the latest frozen version of the artifact in Maven's local repository
- Replace the version of the dependency whith the latest frozen version
- Let the Maven build use the frozen poms instead of the regular poms for all subsequent steps (especially install and deploy)
-
See it in action
- Clone the mvn-fluid-it github project
- 'cd mvn-ext-s-modules'
- Run 'mvn clean install' (First run will build the Maven extensions and will copy these to the $M2_HOME/lib/ext folder)
- Run 'mvn clean install' again (The magic (= the freezing of the snapshots :-)) will now happen because the extensions were installed in the previous step.)
- Have a look at the integration tests in 'mvn-ext-freeze/src/it'
- (To uninstall the extensions just remove the four jars from the $M2_HOME/lib/ext)
-
Links
-