(solved) Maven: CompilationFailureException: Compilation failure


JAVA_HOME が設定されていなかったというありがちなやつですが、次に同じことが起こったときに手間取らないように覚書。

状況

対象: Apache PDFBoxGitHub mirror) 2.0.21

README にしたがって mvn clean install を実行するとコンパイルで失敗する。

スタックトレース:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.6.0:compile (default-compile) on project fontbox: Compilation failure -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.6.0:compile (default-compile) on project fontbox: Compilation failure
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    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:972)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
    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:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure
    at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute (AbstractCompilerMojo.java:1033)
    at org.apache.maven.plugin.compiler.CompilerMojo.execute (CompilerMojo.java:137)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    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:972)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
    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:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)

環境

Ubuntu 18.04
openjdk version "1.8.0_292" (openjdk-8-jdk:amd64)
Apache Maven 3.8.2
maven-compiler-plugin 3.6.0

メモ

-X (--debug) オプションを付けて実行すると詳しい情報が出力される。
今回ヒントになったのはこのあたり:

$ mvn -X clean install

(snip)

[INFO] --- maven-compiler-plugin:3.6.0:compile (default-compile) @ fontbox ---

(snip)

[DEBUG] Configuring mojo 'org.apache.maven.plugins:maven-compiler-plugin:3.6.0:compile' with basic configurator -->
[DEBUG]   (f) basedir = (snip)/pdfbox/fontbox
[DEBUG]   (f) buildDirectory = (snip)/pdfbox/fontbox/target
[DEBUG]   (f) compilePath = [(snip)/pdfbox/fontbox/target/classes, /home/(USER)/.m2/repository/commons-logging/commons-logging/1.2/commons-logging-1.2.jar]
[DEBUG]   (f) compileSourceRoots = [(snip)/pdfbox/fontbox/src/main/java]
[DEBUG]   (f) compilerId = javac
[DEBUG]   (f) debug = true
[DEBUG]   (f) encoding = UTF-8
[DEBUG]   (f) executable = ${env.JAVA_HOME}/bin/javac
[DEBUG]   (f) failOnError = true
[DEBUG]   (f) failOnWarning = false
[DEBUG]   (f) forceJavacCompilerUse = false
[DEBUG]   (f) fork = true
[DEBUG]   (f) generatedSourcesDirectory = (snip)/pdfbox/fontbox/target/generated-sources/annotations
[DEBUG]   (f) mojoExecution = org.apache.maven.plugins:maven-compiler-plugin:3.6.0:compile {execution: default-compile}
[DEBUG]   (f) optimize = false
[DEBUG]   (f) outputDirectory = (snip)/pdfbox/fontbox/target/classes
[DEBUG]   (f) project = MavenProject: org.apache.pdfbox:fontbox:2.0.21 @ (snip)/pdfbox/fontbox/pom.xml
[DEBUG]   (f) projectArtifact = org.apache.pdfbox:fontbox:bundle:2.0.21
[DEBUG]   (f) session = org.apache.maven.execution.MavenSession@31464a43
[DEBUG]   (f) showDeprecation = true
[DEBUG]   (f) showWarnings = false
[DEBUG]   (f) skipMultiThreadWarning = false
[DEBUG]   (f) source = 1.6
[DEBUG]   (f) staleMillis = 0
[DEBUG]   (f) target = 1.6
[DEBUG]   (f) useIncrementalCompilation = true
[DEBUG]   (f) verbose = false
[DEBUG] -- end configuration --
[DEBUG] Using compiler 'javac'.

(snip)

[DEBUG] Excutable: 
[DEBUG]  ${env.JAVA_HOME}/bin/javac
[DEBUG] Command line options:
[DEBUG] (snip) -target 1.6 -source 1.6 -encoding UTF-8

(snip)

javac のパスが

[DEBUG]   (f) executable = ${env.JAVA_HOME}/bin/javac

となっていて、環境変数 JAVA_HOME が期待されているようだったので、

JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 mvn clean install

のように指定したらコンパイルできるようになった。

バージョンが 1.6 となっているのも気にはなって、たぶん正しく指定した方がいいんだろうけどそっちは修正しなくてもよかった。理由は不明。


ついでにメモ。

compile ゴールのヘルプ表示コマンド:

mvn compiler:help -Ddetail=true -Dgoal=compile