web-dev-qa-db-fra.com

Maven: Publication cible non valide: 10

J'essaie de compiler mon projet maven en utilisant Java 10 mais j'ai des problèmes. Dans mon IDE (IntelliJ IDEA) tout est compilé et fonctionne très bien sous Java 10. J'ai installé la dernière version maven version 3.5.4 et a pointé mon Java_HOME à la 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"

La commande maven que j'utilise est la suivante:

mvn package -Dmaven.test.skip

Dans mon pom.xml J'ai eu le suivant pour Java 8 qui a bien fonctionné:

<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>

Pour Java 10 Je l'ai changé comme suit:

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

Cela ne fonctionne pas, comme avec 1.10 comme version du compilateur source et cible.

La sortie de journalisation de débogage complète (-X commutateur de ligne de commande) est le suivant:

[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

Ajout du maven-compiler-plugin comme suggéré dans la réponse this également ne fonctionne pas:

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

Des idées sur la façon de résoudre ce problème?

15
BullyWiiPlaza

Cela a fonctionné pour moi:

<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>

Ceci réponse dit que vous avez besoin de:

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

à l'intérieur de <plugin/> tag, mais le nouveau mvn (3.5.4) doit éviter cela, car je n’en ai pas besoin.

13
David Conrad

Obtenez votre Java en exécutant Java -version.

Vous obtiendrez un résultat comme:

Java version "1.8.0_201"

Allez maintenant dans votre fichier POM et mettez à jour les propriétés de source et de cible de maven-compiler-plugin avec votre version Java version installée. Dans mon cas, il s’agit de 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