tag:crieit.net,2005:https://crieit.net/tags/Maven/feed 「Maven」の記事 - Crieit Crieitでタグ「Maven」に投稿された最近の記事 2021-09-03T06:10:17+09:00 https://crieit.net/tags/Maven/feed tag:crieit.net,2005:PublicArticle/17631 2021-09-03T06:10:17+09:00 2021-09-03T06:10:17+09:00 https://crieit.net/posts/java-Maven-CompilationFailureException-Compilation-failure (solved) Maven: CompilationFailureException: Compilation failure <p><code>JAVA_HOME</code> が設定されていなかったというありがちなやつですが、次に同じことが起こったときに手間取らないように覚書。</p> <h1 id="状況"><a href="#%E7%8A%B6%E6%B3%81">状況</a></h1> <p>対象: <a target="_blank" rel="nofollow noopener" href="https://pdfbox.apache.org/">Apache PDFBox</a>(<a target="_blank" rel="nofollow noopener" href="https://github.com/apache/pdfbox">GitHub mirror</a>) 2.0.21</p> <p>README にしたがって <code>mvn clean install</code> を実行するとコンパイルで失敗する。</p> <p>スタックトレース:</p> <pre><code>[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) </code></pre> <h1 id="環境"><a href="#%E7%92%B0%E5%A2%83">環境</a></h1> <pre><code>Ubuntu 18.04 openjdk version "1.8.0_292" (openjdk-8-jdk:amd64) Apache Maven 3.8.2 maven-compiler-plugin 3.6.0 </code></pre> <h1 id="メモ"><a href="#%E3%83%A1%E3%83%A2">メモ</a></h1> <p><code>-X (--debug)</code> オプションを付けて実行すると詳しい情報が出力される。<br /> 今回ヒントになったのはこのあたり:</p> <pre><code>$ 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) </code></pre> <p>javac のパスが</p> <pre><code>[DEBUG] (f) executable = ${env.JAVA_HOME}/bin/javac </code></pre> <p>となっていて、環境変数 <code>JAVA_HOME</code> が期待されているようだったので、</p> <pre><code>JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 mvn clean install </code></pre> <p>のように指定したらコンパイルできるようになった。</p> <p>バージョンが 1.6 となっているのも気にはなって、たぶん正しく指定した方がいいんだろうけどそっちは修正しなくてもよかった。理由は不明。</p> <hr /> <p>ついでにメモ。</p> <p><code>compile</code> ゴールのヘルプ表示コマンド:</p> <pre><code>mvn compiler:help -Ddetail=true -Dgoal=compile </code></pre> sonota486