DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Using Lombok Library With JDK 23
  • A Maven Story
  • Build a Java Backend That Connects With Salesforce
  • Step By Step Guide To Using Mule ESB

Trending

  • Start Coding With Google Cloud Workstations
  • Automating Data Pipelines: Generating PySpark and SQL Jobs With LLMs in Cloudera
  • Measuring the Impact of AI on Software Engineering Productivity
  • Beyond ChatGPT, AI Reasoning 2.0: Engineering AI Models With Human-Like Reasoning
  1. DZone
  2. Coding
  3. Java
  4. How to Fix Invalid Target Release: 1.7, 1.8, 1.9, or 1.10 Error in Maven Build

How to Fix Invalid Target Release: 1.7, 1.8, 1.9, or 1.10 Error in Maven Build

Trying to build a Java project with Maven but your build keeps failing? Here's why.

By 
Javin Paul user avatar
Javin Paul
·
Dec. 07, 18 · Tutorial
Likes (7)
Comment
Save
Tweet
Share
181.0K Views

Join the DZone community and get the full member experience.

Join For Free

If you are building your Java project using Maven, in Eclipse, or from the command prompt by running mvn install and your build is failing with an error like "invalid target release: 1.7" or "invalid target release: 1.8," then you have come to the right place. In this article, I'll show you why this error occurs and how you can deal with these errors even with higher Java versions, like Java 9 or 10, installed on your machine. The root cause of the problem is that you have specified a higher Java version in your pom.xml file for Maven compiler plugin than what Maven knows in your system, and that's why it's saying invalid target release.

A simple solution to this problem is either to reduce your target version in pom.xml or install a new Java version if you want to build your project in a higher version.

But, the key to solving this problem is knowing that Maven picks the Java version from the JAVA_HOME variable and not from the PATH environment variable. 

This means that even if you have JDK 8 installed but if your JAVA_HOME is still referring to JDK 1.7, then you will get this error.

Thankfully, you can find that out, meaning which version of Java your Maven is using. Just run the mvn -version command from the command prompt and it will print the value of JAVA_HOME variable and confirm which version of the JDK it is using to build your project.

Invalid Target Release: 1.7 

Recently, I was building a Java project using Maven on my old machine when I encountered this error. I thought I had the latest Java version, which I had, and that's why I was surprised by this error.

Here is what my Maven pom.xml looked like:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>


Here is an example output of the mvn -version:

$ mvn -version

Apache Maven 3.2.3 (33f8c3e1027c3ddde99d3cdebad2656a31e8fdf4; 2014-08-12T04:58:10+08:00

Maven home: C:\apache-maven-3.2.3

Java version: 1.6.0_37, vendor: Sun Microsystems Inc.

Java home: C:\jdk1.6.0_37\jre

Default locale: en_US, platform encoding: Cp1252

OS name: "windows 7", version: "6.1", arch: "x86", family: "windows"


You can see that the Maven in my machine was using JDK 1.6.0_37, and that's why, when I was building my Maven project with JDK 1.7 as the target, it was failing.

Once I updated the pom.xml to use target 1.6, the build started working!

Because Java 7 was not required for my project, I just had to change the Maven compile plugin as follows:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>


But if you have to build your Java project with JDK 1.7, then just install and update your JAVA_HOME variable and this error will go away.

This solution is really nice as you can solve the problem immediately. If you want to learn about Maven itself, I suggest you take a look at the Maven Fundamentals by Bryan Hansen course on Pluralsight, one of the better courses to start with when learning Maven.

How to set Java Version for Maven in Windows?

Invalid Target Release: 1.8

This error comes if your maven compiler plugin has <target>1.8</target> but JAVA_HOMEvariable in your machine is referring to a Java version which is lower than JDK 1.8 e.g. JDK 1.6 or JDK 1.7.

The Maven file initially might look like:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>


In order to solve this error, either change your target to match with the Java version your JAVA_HOME variable is referring to or install a new JDK and updated the JAVA_HOME variable.

If you don't know, then see this article to find out exact steps to change the value of JAVA_HOME environment variable in Windows and Linux.

If you are working in a restricted environment, like a big company where software is deployed automatically and can't add or edit an environment variable, you can still change them in the local shell as shown in my earlier article How to set a specific Java version for Maven in Windows.

How to fix invalid target release: 1.7, 1.8, 1.9, or 1.10 Error in Maven Build

Invalid Target Release: 1.9

This error will come if your Maven compiler plugin has <target>1.9</target> but the JAVA_HOME variable in your machine is referring to a Java version that is lower than JDK 1.9, e.g. JDK 1.8 or JDK 1.7.

As explained in the previous section, you either need to change the target into pom.xml or install a new JDK and update the JAVA_HOME environment variable to point out a new JDK bin directory.

Since Maven uses JAVA_HOME, it will not solve the problem until you update this environment variable, even if you have installed the correct version of Java.

Similarly, you will get Invalid target release: 1.10 if you compile using <target>1.10</target> and your JAVA_HOME is referring to JDK 9 or JDK 8.

Now, you can generalize this problem and solve it depending upon which version of Java you have specified in your pom.xml and which version of Java is installed on your machine and referred by the JAVA_HOME environment variable.

Further Learning

Maven Crash Course

Maven Fundamentals by Bryan Hansen

Java Maven: 102 The Truth About Building Java Programs

Other Maven articles you may like:

  • What is the difference between Maven, ANT, and Jenkins? (answer)
  • How to increase the heap size of Maven? (steps)
  • How to fix Maven Eclipse Dependency search not working issue? (solution)
  • How to install Maven in Windows 10? (steps)
  • How to build a Java project using ANT? (article)
  • How to create or modify build.xm in ANT? (tutorial)
  • Top 5 Apache Maven Books for Free (books)
  • 10 Points about Maven Java Developer should know (maven)
  • 10 Maven Plugins Every Java Developers should know (plugins)
  • 6 Free Maven and Jenkins Courses for Java developers (courses)
  • How to set a specific Java version for Maven (tutorial)

Thanks for reading this article! If you manage to solve your problem by following these tips, then please share them with your friends and colleagues. And if you are still facing issues, then please drop a note below and we may be able to solve your problem together.

Apache Maven Java (programming language) Release (computing) Build (game engine) Java Development Kit

Published at DZone with permission of Javin Paul, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Using Lombok Library With JDK 23
  • A Maven Story
  • Build a Java Backend That Connects With Salesforce
  • Step By Step Guide To Using Mule ESB

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!