Maven is known to be a verbose, opinionated framework for building applications, primarily for a Java Stack. In this article we discuss Lime Mojito’s view on maven, and how we use it to produce maintainable, repeatable builds using modern features such as automated testing, AWS stubbing (LocalStack) and deployment. We have OSS standards you can use in your own maven builds at https://bitbucket.org/limemojito/oss-maven-standards/src/master/ and POM’s on maven central.
Before we look at our standards, we set the context of what drives our build design by looking at our technology choices. We’ll cover why our developer builds are setup this way, but not how our Agile Continuous Integration works in this post.
Lime Mojito’s Technology Choices
Lime Mojito uses a Java based technology stack with Spring, provisioned on AWS. We use AWS CDK (Java) for provisioning and our lone exception is for web based user interfaces (UI), where we use Typescript and React with Material UI and AWS Amplify.
Our build system is developer machine first focused, using Maven as the main build system for all components other than the UI.
Build Charter
- The build enforces our development standards to reduce the code review load.
- The build must have a simple developer interface –
mvn clean install
. - If the clean install passes – we can move to source Pull Request (PR).
- PR is important, as when a PR is merged we may automatically deploy to production.
- Creating a new project or module must not require a lot of configuration (“xml hell”).
- A module must not depend on another running Lime Mojito module for testing.
- Any stub resources for testing must be a docker image.
- Postgres, Localstack, etc
- Stubs will be managed by the build process for integration test phase.
- ie if you’re using stubs, you’re building a failsafe maven plugin IT test case.
- The build will handle style and code metric checks (CheckStyle, Maven Enforcer, etc) so that we do not waste time in PR reviews.
- For open source, we will post to Maven Central on a Release Build.
Open Source Standards For Our Maven Builds
Our very “top” level of build standards is open source and available for others to use or be inspired by:
Bitbucket: https://bitbucket.org/limemojito/oss-maven-standards/src/master/
The base POM files are also available on the Maven Central Repository if you want to use our approach in your own builds.
https://repo.maven.apache.org/maven2/com/limemojito/oss/standards/
Maven Example pom.xml for building a JAR library
This example will do all the below with only 6 lines of extra XML in your maven pom.xml file:
- enforce your dependencies are a single java version
- resolve dependencies via the Bill of Materials Library that we use too smooth out our Spring + Spring Boot + Spring Cloud + Spring Function + AWS SDK(s) dependency web.
- Enable Lombok for easier java development with less boilerplate
- Configure code signing
- Configure maven repository deployment locations (I suggest overriding these for your own deployments!)
- Configure CheckStyle for code style checking against our standards at http://standards.limemojito.com/oss-checkstyle.xml
- Configure optional support for docker images loading before integration-test phase
- Configure Project Lombok for Java Development with less boilerplate at compile time.
- Configure logging support with SLF4J
- Build a jar with completed MANIFEST.MF information including version numbers.
- Build javadoc and source jars on a release build
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>my.dns.reversed.project</groupId> <artifactId>my-library</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <parent> <groupId>com.limemojito.oss.standards</groupId> <artifactId>jar-development</artifactId> <version>13.0.4</version> <relativePath/> </parent> </project>
When you add dependencies, common ones that are in or resolved via our library pom.xml do not need version numbers as they are managed by our modern Bill of Materials (BOM) style dependency setup.
Example using the AWS SNS sdk as part of the jar:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>my.dns.reversed.project</groupId> <artifactId>my-library</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <parent> <groupId>com.limemojito.oss.standards</groupId> <artifactId>jar-development</artifactId> <version>13.0.4</version> <relativePath/> </parent> <dependencies> <dependency> <groupId>software.amazon.awssdk</groupId> <artifactId>sns</artifactId> </dependency> </dependencies> </project>
Our Open Source Standards library supports the following module types (archetypes) out of the box:
Type | Description |
java-development | Base POM used to configure deployment locations, checkstyle, enforcer, docker, plugin versions, profiles, etc. Designed to be extended for different archetypes (JAR, WAR, etc.). |
jar-development | Build a jar file with test and docker support |
jar-lamda-development | Build a Spring Boot Cloud Function jar suitable for lambda use (java 17 Runtime) with AWS dependencies added by default. Jar is shaded for simple upload. |
spring-boot-development | Spring boot jar constructed with the base spring-boot-starter and lime mojito aws-utilities for local stack support. |
We hope that you might find these standards interesting to try out.