wake-up-neo.com

Maven: Ungültige Zielversion: 10

Ich versuche mein maven Projekt mit Java 10 zu kompilieren, aber ich habe Probleme. In meinem IDE (IntelliJ IDEA) Kompiliert und läuft alles einwandfrei unter Java 10. Ich habe die neueste maven Version 3.5.4 und zeigte mit meinem Java_HOME auf den JDK 10:

$ mvn --version
Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-17T20:33:14+02:00)
Maven home: C:\Maven\bin\..
Java version: 10.0.2, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk-10.0.2
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", Arch: "AMD64", family: "windows"

Der maven Befehl, den ich benutze, ist:

mvn package -Dmaven.test.skip

In meinem pom.xml Hatte ich Folgendes für Java 8, Was gut funktioniert hat:

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

Für Java 10 Habe ich Folgendes geändert:

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

Dies funktioniert nicht, genauso wie die Verwendung von 1.10 Als Version für den Quell- und Ziel-Compiler.

Die vollständige Ausgabe der Debugprotokollierung (Befehlszeilenoption -X) Lautet wie folgt:

[ERROR] Failed to execute goal org.Apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project My-Project: Fatal error compiling: invalid target release: 1.10 -> [Help 1]
org.Apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.Apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project My-Project: Fatal error compiling
    at org.Apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.Java:213)
    at org.Apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.Java:154)
    at org.Apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.Java:146)
    at org.Apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.Java:117)
    at org.Apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.Java:81)
    at org.Apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.Java:56)
    at org.Apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.Java:128)
    at org.Apache.maven.DefaultMaven.doExecute (DefaultMaven.Java:305)
    at org.Apache.maven.DefaultMaven.doExecute (DefaultMaven.Java:192)
    at org.Apache.maven.DefaultMaven.execute (DefaultMaven.Java:105)
    at org.Apache.maven.cli.MavenCli.execute (MavenCli.Java:954)
    at org.Apache.maven.cli.MavenCli.doMain (MavenCli.Java:288)
    at org.Apache.maven.cli.MavenCli.main (MavenCli.Java:192)
    at Sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at Sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.Java:62)
    at Sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.Java:43)
    at Java.lang.reflect.Method.invoke (Method.Java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.Java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.Java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.Java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.Java:356)
Caused by: org.Apache.maven.plugin.MojoExecutionException: Fatal error compiling
    at org.Apache.maven.plugin.compiler.AbstractCompilerMojo.execute (AbstractCompilerMojo.Java:1086)
    at org.Apache.maven.plugin.compiler.CompilerMojo.execute (CompilerMojo.Java:168)
    at org.Apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.Java:137)
    at org.Apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.Java:208)
    at org.Apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.Java:154)
    at org.Apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.Java:146)
    at org.Apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.Java:117)
    at org.Apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.Java:81)
    at org.Apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.Java:56)
    at org.Apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.Java:128)
    at org.Apache.maven.DefaultMaven.doExecute (DefaultMaven.Java:305)
    at org.Apache.maven.DefaultMaven.doExecute (DefaultMaven.Java:192)
    at org.Apache.maven.DefaultMaven.execute (DefaultMaven.Java:105)
    at org.Apache.maven.cli.MavenCli.execute (MavenCli.Java:954)
    at org.Apache.maven.cli.MavenCli.doMain (MavenCli.Java:288)
    at org.Apache.maven.cli.MavenCli.main (MavenCli.Java:192)
    at Sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at Sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.Java:62)
    at Sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.Java:43)
    at Java.lang.reflect.Method.invoke (Method.Java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.Java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.Java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.Java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.Java:356)
Caused by: org.codehaus.plexus.compiler.CompilerException: invalid target release: 1.10
    at org.codehaus.plexus.compiler.javac.JavaxToolsCompiler.compileInProcess (JavaxToolsCompiler.Java:173)
    at org.codehaus.plexus.compiler.javac.JavacCompiler.performCompile (JavacCompiler.Java:174)
    at org.Apache.maven.plugin.compiler.AbstractCompilerMojo.execute (AbstractCompilerMojo.Java:1075)
    at org.Apache.maven.plugin.compiler.CompilerMojo.execute (CompilerMojo.Java:168)
    at org.Apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.Java:137)
    at org.Apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.Java:208)
    at org.Apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.Java:154)
    at org.Apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.Java:146)
    at org.Apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.Java:117)
    at org.Apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.Java:81)
    at org.Apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.Java:56)
    at org.Apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.Java:128)
    at org.Apache.maven.DefaultMaven.doExecute (DefaultMaven.Java:305)
    at org.Apache.maven.DefaultMaven.doExecute (DefaultMaven.Java:192)
    at org.Apache.maven.DefaultMaven.execute (DefaultMaven.Java:105)
    at org.Apache.maven.cli.MavenCli.execute (MavenCli.Java:954)
    at org.Apache.maven.cli.MavenCli.doMain (MavenCli.Java:288)
    at org.Apache.maven.cli.MavenCli.main (MavenCli.Java:192)
    at Sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at Sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.Java:62)
    at Sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.Java:43)
    at Java.lang.reflect.Method.invoke (Method.Java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.Java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.Java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.Java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.Java:356)
Caused by: Java.lang.IllegalArgumentException: invalid target release: 1.10
    at com.Sun.tools.javac.main.OptionHelper$GrumpyHelper.error (OptionHelper.Java:103)
    at com.Sun.tools.javac.main.Option$12.process (Option.Java:216)
    at com.Sun.tools.javac.api.JavacTool.processOptions (JavacTool.Java:217)
    at com.Sun.tools.javac.api.JavacTool.getTask (JavacTool.Java:156)
    at com.Sun.tools.javac.api.JavacTool.getTask (JavacTool.Java:107)
    at com.Sun.tools.javac.api.JavacTool.getTask (JavacTool.Java:64)
    at org.codehaus.plexus.compiler.javac.JavaxToolsCompiler.compileInProcess (JavaxToolsCompiler.Java:125)
    at org.codehaus.plexus.compiler.javac.JavacCompiler.performCompile (JavacCompiler.Java:174)
    at org.Apache.maven.plugin.compiler.AbstractCompilerMojo.execute (AbstractCompilerMojo.Java:1075)
    at org.Apache.maven.plugin.compiler.CompilerMojo.execute (CompilerMojo.Java:168)
    at org.Apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.Java:137)
    at org.Apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.Java:208)
    at org.Apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.Java:154)
    at org.Apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.Java:146)
    at org.Apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.Java:117)
    at org.Apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.Java:81)
    at org.Apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.Java:56)
    at org.Apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.Java:128)
    at org.Apache.maven.DefaultMaven.doExecute (DefaultMaven.Java:305)
    at org.Apache.maven.DefaultMaven.doExecute (DefaultMaven.Java:192)
    at org.Apache.maven.DefaultMaven.execute (DefaultMaven.Java:105)
    at org.Apache.maven.cli.MavenCli.execute (MavenCli.Java:954)
    at org.Apache.maven.cli.MavenCli.doMain (MavenCli.Java:288)
    at org.Apache.maven.cli.MavenCli.main (MavenCli.Java:192)
    at Sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at Sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.Java:62)
    at Sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.Java:43)
    at Java.lang.reflect.Method.invoke (Method.Java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.Java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.Java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.Java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.Java:356)
[ERROR]
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.Apache.org/confluence/display/MAVEN/MojoExecutionException

Das Hinzufügen des maven-compiler-plugin Wie in diese Antwort vorgeschlagen funktioniert auch nicht:

Fatal error compiling: invalid flag: --release -> [Help 1]

Irgendwelche Ideen zur Behebung dieses Problems?

15
BullyWiiPlaza

Das hat bei mir funktioniert:

<build>
    <plugins>
        <plugin>
            <groupId>org.Apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.7.0</version>
            <configuration>
                <release>10</release>
            </configuration>
        </plugin>
    </plugins>
</build>

Dies Antwort sagt, dass Sie brauchen:

<dependencies>
    <dependency>
        <groupId>org.ow2.asm</groupId>
        <artifactId>asm</artifactId>
        <version>6.2</version> <!-- Use newer version of ASM -->
    </dependency>
</dependencies>

in der <plugin/> tag, aber das neuere mvn (3.5.4) muss das umgehen, da ich es nicht brauchte.

13
David Conrad

Holen Sie sich Ihre Java Version durch Ausführen von Java -version.

Sie erhalten eine Ausgabe wie:

Java version "1.8.0_201"

Wechseln Sie jetzt zu Ihrer POM-Datei und aktualisieren Sie die Quell- und Zieleigenschaften von maven-compiler-plugin mit Ihrer installierten Java Version. In meinem Fall ist es 1.8

<plugin>
   <groupId>org.Apache.maven.plugins</groupId>
   <artifactId>maven-compiler-plugin</artifactId>
   <configuration>
      <source>1.8</source>
      <target>1.8</target>
   </configuration>
</plugin>
3
LanilT