Home » Java » Core Java » Maven and Java multi-version modules

About Vlad Mihalcea

Vlad Mihalcea is a software architect passionate about software integration, high scalability and concurrency challenges.

Maven and Java multi-version modules


Usually, a project has a minimum Java version requirement and that applies to all of its modules. But every rule has its exceptions, as recently I stumbled on the following issue.

One open source project of mine mandates Java 1.6 for most of its modules, except one requiring the 1.7 version.

This happens when integrating external libraries having different Java requirements than your own project.

Because that one module integrates the DBCP2 framework (supporting at least Java 1.7), I need to instruct Maven to use two different Java compilers.

Environment variables

We need to define the following environment variables

Environment Variable NameEnvironment Variable Value
JAVA_HOME_6C:\Program Files\Java\jdk1.6.0_38
JAVA_HOME_7C:\Program Files\Java\jdk1.7.0_25

The parent pom.xml

The parent pom.xml defines the global java version settings


We need to instruct both the compiler and the test plugins to use the configured java version.


The specific module pom.xml

Those modules requiring a different java version, just need to override the default settings:


And that’s it, we can now build each modules using its own specific minimum java version requirement.

Reference: Maven and Java multi-version modules from our JCG partner Vlad Mihalcea at the Vlad Mihalcea’s Blog blog.

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!


1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design


and many more ....




  1. Do you really need different JDKs? Can’t you just specify source and target versions and use JDK7?

  2. I really really need different JDKs, that’s an open source trait I cannot escape. When we develop commercial software, the project scope is quite narrow, so it makes sense to benefit from the latest advancements in the Java language. Open source frameworks are designed for larger scopes, and since there are still many platforms that haven’t yet migrated to 1.7, it’s wise to support 1.6 too.

Leave a Reply

Your email address will not be published. Required fields are marked *


Want to take your Java Skills to the next level?
Grab our programming books for FREE!
  • Save time by leveraging our field-tested solutions to common problems.
  • The books cover a wide range of topics, from JPA and JUnit, to JMeter and Android.
  • Each book comes as a standalone guide (with source code provided), so that you use it as reference.
Last Step ...

Where should we send the free eBooks?

Good Work!
To download the books, please verify your email address by following the instructions found on the email we just sent you.