3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

herokuのpushでJavaのCompilerがversion 1.5になってラムダ式を使うとコンパイルエラーが発生するときの対処方法

Posted at

事象

herokuのjavaアプリケーションをgit push heroku masterでデプロイする際に、mavenのjavaのコンパイラが-source 1.5となり、ラムダ式を受け付けてくれなくなることがあったので、その対処方法をメモ

remote:        [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ helloworld ---
remote:        [INFO] 
remote:        [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ helloworld ---
remote:        [INFO] Using 'UTF-8' encoding to copy filtered resources.
remote:        [INFO] Copying 1 resource
remote:        [INFO] 
remote:        [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ helloworld ---
remote:        [INFO] Changes detected - recompiling the module!
remote:        [INFO] Compiling 20 source files to /tmp/build_87cf46c0b2782adde23c08b558684ff6/target/classes
remote:        [INFO] -------------------------------------------------------------
remote:        [ERROR] COMPILATION ERROR : 
remote:        [INFO] -------------------------------------------------------------
remote:        [ERROR] /tmp/build_87cf46c0b2782adde23c08b558684ff6/src/main/java/xxxxxxxx/XxxxxYyyyyZzzzz.java:[60,42] lambda expressions are not supported in -source 1.5 ← ここでラムダ式を使ったソースがエラー
remote:          (use -source 8 or higher to enable lambda expressions)
remote:        [INFO] 1 error
remote:        [INFO] -------------------------------------------------------------
remote:        [INFO] ------------------------------------------------------------------------
remote:        [INFO] BUILD FAILURE
remote:        [INFO] ------------------------------------------------------------------------
remote:        [INFO] Total time: 12.493 s
remote:        [INFO] Finished at: 2015-05-06T11:54:00+00:00
remote:        [INFO] Final Memory: 16M/418M
remote:        [INFO] ------------------------------------------------------------------------
remote:        [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project helloworld: Compilation failure
remote:        [ERROR] /tmp/build_87cf46c0b2782adde23c08b558684ff6/src/main/java/xxxxxxxx/XxxxxYyyyyZzzzz.java:[60,42] lambda expressions are not supported in -source 1.5
remote:        [ERROR] (use -source 8 or higher to enable lambda expressions)
remote:        [ERROR] -> [Help 1]
remote:        [ERROR] 
remote:        [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
remote:        [ERROR] Re-run Maven using the -X switch to enable full debug logging.
remote:        [ERROR] 
remote:        [ERROR] For more information about the errors and possible solutions, please read the following articles:
remote:        [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
remote: 
remote:  !     ERROR: Failed to build app with Maven
remote:        We're sorry this build is failing! If you can't find the issue in application code,
remote:        please submit a ticket so we can help: https://help.heroku.com/
remote: 
remote: 
remote:  !     Push rejected, failed to compile Java app
remote: 
remote: Verifying deploy....
remote: 
remote: !	Push rejected to dry-bayou-9999.
remote: 
To https://git.heroku.com/dry-bayou-9999.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/dry-bayou-9999.git'

原因

コンパイル時にjavaのversionで1.5が指定されて、ラムダ式が認識されないようだ。
(1.5というのは古すぎるような)

対応方法

mavenのpom.xmlに以下を追加

<properties>
  <maven.compiler.source>1.8</maven.compiler.source>
  <maven.compiler.target>1.8</maven.compiler.target>
</properties>

または、

       <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>

参考

How to change Java version for Maven in IntelliJ?
MavenでJava8のプロジェクトを作る

感想

IntelliJだとこの辺りを微妙に吸収してくれていたようなので、あんまり気づかなかった。

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?