web-dev-qa-db-ja.com

Maven:無効なターゲットリリース:10

maven プロジェクトを Java 10 を使用してコンパイルしようとしていますが、問題があります。私のIDE(IntelliJ IDEA)では、すべてがJava 10の下で正常にコンパイルおよび実行されます。最新のmavenバージョン3.5.4をインストールし、Java_HOMEJDK 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"

私が使用するmavenコマンドは次のとおりです。

mvn package -Dmaven.test.skip

pom.xmlには、Java 8に対して次のものがあり、うまくいきました。

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

Java 10については、次のように変更しました。

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

これは、ソースコンパイラとターゲットコンパイラのバージョンとして1.10を使用するのと同じように機能しません。

完全なデバッグログ出力(-Xコマンドラインスイッチ)は次のとおりです。

[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

this answerで提案されているようなmaven-compiler-pluginを追加しても機能しません:

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

この問題を修正する方法についてのアイデアはありますか?

15
BullyWiiPlaza

これは私のために働いた:

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

これは answer が必要だということです:

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

<plugin/>タグ内にありますが、新しいmvn(3.5.4)では不要であるため、これを回避する必要があります。

13
David Conrad

Java -versionを実行して、Javaバージョンを取得します。

次のような出力が得られます。

Java version "1.8.0_201"

POMファイルに移動し、maven-compiler-pluginのソースとターゲットのプロパティを、インストール済みのJavaバージョンで更新します。私の場合は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