web-dev-qa-db-ja.com

Maven 3.8.0コンパイラ-致命的なエラーのコンパイル:リリースバージョン11はサポートされていません

最新バージョンのmaven-compiler-pluginでJava 11を使用してビルドすることはできません。

pom.xml:

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

mavenを使用してビルドしようとすると:

➜  mvn clean compile
[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] Building service 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ service ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 80 source files to /home/mip/service/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.859 s
[INFO] Finished at: 2018-08-01T11:20:55+01:00
[INFO] Final Memory: 32M/124M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.Apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project service: Fatal error compiling: release version 11 not supported -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[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

以下は、私が使用しているMavenおよびJavaバージョンです。

➜  mvn -version
Apache Maven 3.5.2
Maven home: /usr/share/maven
Java version: 10.0.1, vendor: Oracle Corporation
Java home: /usr/lib/jvm/Java-11-openjdk-AMD64
Default locale: en_GB, platform encoding: UTF-8
OS name: "linux", version: "4.15.0-29-generic", Arch: "AMD64", family:     "unix"
➜  /usr/lib/jvm/Java-11-openjdk-AMD64/bin/Java -version
openjdk version "10.0.1" 2018-04-17
OpenJDK Runtime Environment (build 10.0.1+10-Ubuntu-3ubuntu1)
OpenJDK 64-Bit Server VM (build 10.0.1+10-Ubuntu-3ubuntu1, mixed mode)

Java 11が自分自身を「10.0.1」と識別して問題を引き起こしている可能性はありますか? pom.xmlを<release>10</release>に変更すると、Java 10がインストールされていなくても問題なくビルドされます。

➜  ~ /usr/lib/jvm/Java-11-openjdk-AMD64/bin/javac -version
javac 10.0.1 

➜ javac --release 11 SomeClass.Java
javac: release version 11 not 
supported Usage: javac <options> <source files>
use --help for a list of possible options

これはUbuntu openjdk-11-jdkパッケージの問題だと思います。

➜  ~ Sudo apt install openjdk-11-jdk
Reading package lists... Done
Building dependency tree       
Reading state information... Done
openjdk-11-jdk is already the newest version (10.0.1+10-3ubuntu1).
0 to upgrade, 0 to newly install, 0 to remove and 2 not to upgrade.
20
mip

mvnを設定するにはJava_HOMEが必要です。私は同じ問題に直面し、Java_HOMEをセットアップしてJDKを修正することでうまくいきました。

12
Ankit Bhartiya

私にとってこれは、JDKではなくJava 11 JREがインストールされていることに起因しています。フォルダー名には「jdk」が含まれていたため、正しいと仮定しましたが、/binフォルダーを見るとjavac実行可能ファイルが表示されなかったため、デフォルトに戻ったと思いますJavaより前のシステム上のJava 11。

1
KC Baltz

ターミナル内:

mvn -version

例-Javaバージョン:9.0.4

さらに使用されるプラグイン:

<plugins>
<plugin>
<groupId>org.Apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>9.0.4</release>
</configuration>
</plugin>
</plugins>
0