gs-maven: mvn compile throws errors

Hello,

I’m working on this guide, but when I run mvn compile I get the following error:

[ERROR] Source option 1.5 is no longer supported. Use 1.6 or later.
[ERROR] Target option 1.5 is no longer supported. Use 1.6 or later.

I’m on OS X. mvn -v shows:

Maven home: /Users/matthuntington/Desktop/apache-maven-3.5.0
Java version: 9, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.12.6", arch: "x86_64", family: "mac"

echo $JAVA_HOME shows:

/Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home

echo $PATH shows:

/Users/matthuntington/Desktop/apache-maven-3.5.0/bin/:/Users/matthuntington/.rbenv/bin:/Users/matthuntington/.rbenv/shims:/Users/matthuntington/anaconda/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin

any suggestions? Thanks!

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 23
  • Comments: 34 (1 by maintainers)

Commits related to this issue

Most upvoted comments

Solution: I added

<properties>
    <maven.compiler.source>1.6</maven.compiler.source>
    <maven.compiler.target>1.6</maven.compiler.target>
  </properties>

inside the project tag in pom.xml

mahuntington great solution . Just add in pom

<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
 </properties>

and it will compile

<properties>
  <maven.compiler.source>1.8</maven.compiler.source>
  <maven.compiler.target>1.8</maven.compiler.target>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

One thing everyone missed to explain for the newbies: When the error states that “version 5 or 1.5” isn’t supported, it’s saying that Maven is trying to compile the java code using the JDK (java developer kit) version 1.5, ans it’s not supported.

I had a similar problem: source option 6 is no longer supported use 7 or later target option 6 is no longer supported use 7 or later

this snippet solved it for me <properties> <maven.compiler.source>1.8</maven.compiler.source <maven.compiler.target>1.8</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties>

add it in the pom.xml, properties section Ctrl+S and voila!

Use JavaServlet 3.0-alpha-1 https://mvnrepository.com/artifact/javax.servlet/servlet-api/3.0-alpha-1

<!-- https://mvnrepository.com/artifact/javax.servlet/servlet-api -->
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>3.0-alpha-1</version>
    <scope>provided</scope>
</dependency>

A lot of things to think for a person who is beginning to use maven. Thank you @mahuntington .

@mahuntington Thanks for solution

Solution: I added

<properties>
    <maven.compiler.source>1.6</maven.compiler.source>
    <maven.compiler.target>1.6</maven.compiler.target>
  </properties>

inside the project tag in pom.xml

@mahuntington Works for me. Thanks a lot!

Can you explain the reason of the error? I also get the same error.

Why does your solution solve the problem?

Thanks.

The reason for the error: maven compiler is a plugin inside the maven system. In the compile life cycle phase, maven takes the java version as configured in maven compiler plugin in the pom. When we have not specified the compiler plugin in the pom it takes the default compiler plugin which comes with maven versions. (eg: maven 2 comes with compiler version 1.4) If we want to use the latest java version at compile time need to provide it as follows

<properties> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> </properties>

https://maven.apache.org/plugins/maven-compiler-plugin/

@mahuntington thanks it works for me.

Worked for me. thanks, Matt Huntington for an easy solution.

I think the latest version of maven doesn’t support 1.5 anymore. You have to explicitly tell it which version to compile to. Not entirely sure, though.