Lately we’ve had a few instances at my current client where we’ve had problems with deployment of Java web apps which have been built using the wrong JDK version. We are using Atlassian Bamboo for continuous integration on our daily builds, but we have not yet set up automated releases using Bamboo. Thus, we still have developers creating releases on their individual workstations instead of on a dedicated build machine or cluster. The problem with this is that if an individual developer is not careful with his/her environment set up, they can inadvertently build a release using the wrong JDK version.
I recently discovered that the Maven Enforcer plugin can help prevent this from happening. Configuring it in your Maven build is really quite easy. I’ve included an example below that shows how to require that your Java project be built using Java 1.7.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
<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/maven-v4_0_0.xsd"> <!-- ... --> <build> <plugins> <!-- ... --> <!-- Require Java 1.7 until we move up to Java 1.8 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-enforcer-plugin</artifactId> <version>1.3.1</version> <executions> <execution> <id>enforce-java-version</id> <goals> <goal>enforce</goal> </goals> <configuration> <rules> <requireJavaVersion> <!-- Version must be >= 1.7, but less than 1.8 for now --> <version>[1.7,1.8)</version> <message>>>>>> ${project.artifactId} requires Java 1.7.x <<<<<</message> </requireJavaVersion> </rules> </configuration> </execution> </executions> </plugin> <!-- ... --> </plugins> <!-- ... --> </build> <!-- ... --> </project> |