25

I see lots of answers to this question but they don't work for me. I installed Visual Studio Code, latest version of Java and Maven on my PC and I was able to successfully build my application with Maven on the PC. I then went through the same steps on my Mac and I get this error.

Fresh versions of Macos, Visual Studio Code, Maven and Java. Like all the others have said, I added these lines to the properties section of my pom.xml file:

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

Still get the same error. Here is the relevant output from the mvn build:

alberts-mbp:com.versabuilt.rushmore.process albertyoungwerth$ mvn package
[INFO] Scanning for projects...
[INFO] 
[INFO] ---------< com.versabuilt.rushmore.process:VersaBuiltProcess >----------
[INFO] Building VersaBuilt Process 0.2.18
[INFO] -------------------------------[ bundle ]-------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) @ VersaBuiltProcess ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 5 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.6.0:compile (default-compile) @ VersaBuiltProcess ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 10 source files to /Users/albertyoungwerth/rushmore/com.versabuilt.rushmore.process/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] Source option 6 is no longer supported. Use 7 or later.
[ERROR] Target option 6 is no longer supported. Use 7 or later.
[INFO] 2 errors

I have also restarted Visual Studio Code to no avail.

Kirby
  • 15,127
  • 10
  • 89
  • 104
Al Youngwerth
  • 491
  • 1
  • 4
  • 6
  • What version of Java did you install? I'm ***guessing*** Java 6. But I don't know. – Elliott Frisch May 18 '20 at 01:23
  • Check `java -version` on your computer and check the JVM configuration in the VS code. – PatrickChen May 18 '20 at 01:31
  • It would be worthwhile to include versions for both `mvn` and `javac` in your question - simply saying fresh version does not help. Also useful if you can provide a link to an example project. – I Stevenson May 18 '20 at 02:08
  • java version "14.0.1" 2020-04-14 – Al Youngwerth May 19 '20 at 00:41
  • Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f) Maven home: /Applications/apache-maven-3.6.3 Java version: 14.0.1, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk-14.0.1.jdk/Contents/Home – Al Youngwerth May 19 '20 at 00:42

7 Answers7

24

The last build system I used was called make, so it's been a while since I debugged a build process. I don't remember make dumping 62Kb of debug output either...

Anywho, searching for the keyword "source" (clue being that was one of the tags I was supposed to add) got me to this in the maven debug output:

[DEBUG] (f) source = 1.6

Ahaaa! the source compiler version had not changed like I asked it to with the edit in my original question! I'll bet the maven folks changed the location of the xml tag! Sure enough, searching for 1.6 in the pom.xml file I find this:

    <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.6.0</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>

I changed the source and target tag values to 1.8 and it worked! I also tried deleting the source and target tags in the build plugins scope and left in the maven.compiler.source/target values set to 1.8 and that also worked.

So moral of the story, be careful of extra source or target tags in your pom.xml file!

Al Youngwerth
  • 491
  • 1
  • 4
  • 6
15

Actually, I too faced the above error message, after adding this to property file, Error got resolved. :)

property need to be added in pom.xml

 <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>
TT.
  • 15,774
  • 6
  • 47
  • 88
Gomathy M
  • 338
  • 2
  • 10
3
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <source>1.7</source>
        <target>1.7</target>
    </configuration>
</plugin>
KIRAN
  • 31
  • 1
2

I corrected this problem by matching the jdk between my IDE and the pom.xml file.

0

Sometimes changing from Kotlin to java or inverted.

You can also change or java version to a higher one.

At least that worked for me.

0

go to your project properties and go to sources. then in Source/binary format it will be JDK 5 or 6 etc. but click and make it the higher version. you are done.:)

Ankit
  • 1
-1

Changing maven compiler version in pom file solved my issue. <maven.compiler.source>11</maven.compiler.source> <maven.compiler.target>11</maven.compiler.target>

Maknaka
  • 29
  • 2
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Felix Arnold Feb 03 '22 at 15:08