Laying down the law with the Maven Enforcer Plugin
15 Jun 2016
We recently moved an application to a new server, with an updated installation of Java 8. It didn’t take long to discover that Amazon S3 accesses were failing with an authentication error, and it didn’t take much longer to discover that this problem was already fixed in the version of the AWS Java SDK we were using.
com.amazonaws.services.s3.model.AmazonS3Exception: AWS authentication requires a valid Date or x-amz-date header
The real problem was that we had many dependencies on different versions of Joda Time, and AWS had lost the battle - we were actually running Joda Time 2.0.
It was time to stop this happening again, with the Maven Enforcer Plugin. It’s possible to fail the build if we ever reference two versions of the same dependency:
Of course, this reveals many other problems. There are a lot of libraries which will fail enforcement all by themselves. For example, Jasper Reports includes two versions of Apache Commons Beanutils:
+-uk.co.humboldt:OurApplication:0.0.1-SNAPSHOT
+-net.sf.jasperreports:jasperreports:6.2.0
+-commons-beanutils:commons-beanutils:1.9.0
and
+-uk.co.humboldt:OurApplication:0.0.1-SNAPSHOT
+-net.sf.jasperreports:jasperreports:6.2.0
+-commons-digester:commons-digester:2.1
+-commons-beanutils:commons-beanutils:1.8.3
In fact, Jasper Reports was by far the worst offender in our code base, due to the sheer number of other libraries pulled in. Jasper also disagreed with our version of Jackson and our version of Spring framework. I also killed Commons Logging, as the application uses SLF4J. The tamed version of the Jasper dependency now looks like this: