herokuでjava11のSpringBootアプリケーションをデプロイした際にjava8でビルドされてしまいエラーになってしまう問題の解決方法

技術

はじめに

表題のとおりの記事になります

問題

SpringBootアプリケーションをjava11で開発していたが、herokuにデプロイした際にjava8でビルドされてしまい、以下のようなエラーが出た

-----> Building on the Heroku-20 stack
-----> Determining which buildpack to use for this app
-----> Gradle app detected
-----> Spring Boot detected
-----> Installing JDK 1.8... done
-----> Building Gradle app...
-----> executing ./gradlew build -x check
       ./gradlew: 39: cd: can't cd to "./
       Downloading https://services.gradle.org/distributions/gradle-6.8.3-bin.zip
       ..........10%..........20%..........30%...........40%..........50%..........60%..........70%...........80%..........90%..........100%
       To honour the JVM settings for this build a single-use Daemon process will be forked. See https://docs.gradle.org/6.8.3/userguide/gradle_daemon.html#sec:disabling_the_daemon.
       Daemon will be stopped at the end of the build 
       > Task :compileJava FAILED
       
       FAILURE: Build failed with an exception.
       
       * What went wrong:
       Execution failed for task ':compileJava'.
       > Could not target platform: 'Java SE 11' using tool chain: 'JDK 8 (1.8)'.

解決方法

アプリケーションリポジトリ直下(build.gradleやpom.xmlと同じ階層)に以下の内容のsystem.propertiesを配置してデプロイしたら解決した。javaは11を使うように指定している

java.runtime.version=11

成功のログは以下になる

remote: -----> Building on the Heroku-20 stack
remote: -----> Determining which buildpack to use for this app
remote: -----> Gradle app detected
remote: -----> Spring Boot detected
remote: -----> Installing JDK 11... done
remote: -----> Building Gradle app...
remote: -----> executing ./gradlew build -x check
remote:        ./gradlew: 39: cd: can't cd to "./
remote:        Downloading https://services.gradle.org/distributions/gradle-6.8.3-bin.zip
remote:        ..........10%..........20%..........30%...........40%..........50%..........60%..........70%...........80%..........90%..........100%
remote:        To honour the JVM settings for this build a single-use Daemon process will be forked. See https://docs.gradle.org/6.8.3/userguide/gradle_daemon.html#sec:disabling_the_daemon.
remote:        Daemon will be stopped at the end of the build 
remote:        > Task :compileJava
remote:        > Task :processResources
remote:        > Task :classes
remote:        > Task :bootJarMainClassName
remote:        > Task :bootJar
remote:        > Task :jar SKIPPED
remote:        > Task :assemble
remote:        > Task :build
remote:        
remote:        Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
remote:        Use '--warning-mode all' to show the individual deprecation warnings.
remote:        See https://docs.gradle.org/6.8.3/userguide/command_line_interface.html#sec:command_line_warnings
remote:        
remote:        BUILD SUCCESSFUL in 51s
remote:        4 actionable tasks: 4 executed
remote: -----> Discovering process types
remote:        Procfile declares types     -> (none)
remote:        Default types for buildpack -> web
remote: 
remote: -----> Compressing...
remote:        Done: 93.2M
remote: -----> Launching...
remote:        Released v3
remote:        https://xxx.herokuapp.com/ deployed to Heroku
remote: 
remote: Verifying deploy... done.
To https://git.heroku.com/xxx.git
 * [new branch]      main -> main

👍 🎉

コメント

タイトルとURLをコピーしました