質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.47%
Spring

Spring Framework は、Javaプラットフォーム向けのオープンソースアプリケーションフレームワークです。 Java Platform上に、 Web ベースのアプリケーションを設計するための拡張機能が数多く用意されています。

Gradle

Gradleは、ビルド自動化ツールです。 ソフトウェアパッケージやドキュメント、 または実際に何か他の種類のプロジェクトの構築、テスト、公開、展開などを自動化が出来ます

Q&A

解決済

1回答

146閲覧

SpringプロジェクトをHerokuへデプロイした時にエラーが出ているので解消したいです。

hfuob

総合スコア8

Spring

Spring Framework は、Javaプラットフォーム向けのオープンソースアプリケーションフレームワークです。 Java Platform上に、 Web ベースのアプリケーションを設計するための拡張機能が数多く用意されています。

Gradle

Gradleは、ビルド自動化ツールです。 ソフトウェアパッケージやドキュメント、 または実際に何か他の種類のプロジェクトの構築、テスト、公開、展開などを自動化が出来ます

0グッド

1クリップ

投稿2024/04/19 13:39

編集2024/04/20 03:38

実現したいこと

Springプロジェクトを作成し、Herokuにデプロイしましたがエラーが出ています。

発生している問題・分からないこと

デプロイした時にエラーが発生します。( > Could not resolve all artifacts for configuration ':classpath'.・・・)
エラーの原因として予想は、下記の問題なのかと思うのですが、解決できません。
・おそらくgradleのバージョンとSpring もしくはJavaのバージョンが合ってない?
・build.gradleの設定ができていない。

エラーメッセージ

error

1-----> Building on the Heroku-22 stack 2-----> Determining which buildpack to use for this app 3-----> Gradle app detected 4-----> Spring Boot detected 5-----> Installing OpenJDK 1.8... done 6-----> Building Gradle app... 7-----> executing ./gradlew build -x check 8 Downloading https://services.gradle.org/distributions/gradle-8.7-bin.zip 9 ............10%.............20%.............30%.............40%............50%.............60%.............70%.............80%.............90%............100% 10 To honour the JVM settings for this build a single-use Daemon process will be forked. For more on this, please refer to https://docs.gradle.org/8.7/userguide/gradle_daemon.html#sec:disabling_the_daemon in the Gradle documentation. 11 Daemon will be stopped at the end of the build 12 13 FAILURE: Build failed with an exception. 14 15 * What went wrong: 16 A problem occurred configuring root project 'kintai'. 17 > Could not resolve all artifacts for configuration ':classpath'. 18 > Could not resolve org.springframework.boot:spring-boot-gradle-plugin:3.2.4. 19 Required by: 20 project : > org.springframework.boot:org.springframework.boot.gradle.plugin:3.2.4 21 > No matching variant of org.springframework.boot:spring-boot-gradle-plugin:3.2.4 was found. The consumer was configured to find a library for use during runtime, compatible with Java 8, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '8.7' but: 22 - Variant 'apiElements' declares a library, packaged as a jar, and its dependencies declared externally: 23 - Incompatible because this component declares a component for use during compile-time, compatible with Java 17 and the consumer needed a component for use during runtime, compatible with Java 8 24 - Other compatible attribute: 25 - Doesn't say anything about org.gradle.plugin.api-version (required '8.7') 26 - Variant 'javadocElements' declares a component for use during runtime, and its dependencies declared externally: 27 - Incompatible because this component declares documentation and the consumer needed a library 28 - Other compatible attributes: 29 - Doesn't say anything about its elements (required them packaged as a jar) 30 - Doesn't say anything about its target Java version (required compatibility with Java 8) 31 - Doesn't say anything about org.gradle.plugin.api-version (required '8.7') 32 - Variant 'mavenOptionalApiElements' declares a library, packaged as a jar, and its dependencies declared externally: 33 - Incompatible because this component declares a component for use during compile-time, compatible with Java 17 and the consumer needed a component for use during runtime, compatible with Java 8 34 - Other compatible attribute: 35 - Doesn't say anything about org.gradle.plugin.api-version (required '8.7') 36 - Variant 'mavenOptionalRuntimeElements' declares a library for use during runtime, packaged as a jar, and its dependencies declared externally: 37 - Incompatible because this component declares a component, compatible with Java 17 and the consumer needed a component, compatible with Java 8 38 - Other compatible attribute: 39 - Doesn't say anything about org.gradle.plugin.api-version (required '8.7') 40 - Variant 'runtimeElements' declares a library for use during runtime, packaged as a jar, and its dependencies declared externally: 41 - Incompatible because this component declares a component, compatible with Java 17 and the consumer needed a component, compatible with Java 8 42 - Other compatible attribute: 43 - Doesn't say anything about org.gradle.plugin.api-version (required '8.7') 44 - Variant 'sourcesElements' declares a component for use during runtime, and its dependencies declared externally: 45 - Incompatible because this component declares documentation and the consumer needed a library 46 - Other compatible attributes: 47 - Doesn't say anything about its elements (required them packaged as a jar) 48 - Doesn't say anything about its target Java version (required compatibility with Java 8) 49 - Doesn't say anything about org.gradle.plugin.api-version (required '8.7') 50 51 * Try: 52 > Review the variant matching algorithm at https://docs.gradle.org/8.7/userguide/variant_attributes.html#sec:abm_algorithm. 53 > No matching variant errors are explained in more detail at https://docs.gradle.org/8.7/userguide/variant_model.html#sub:variant-no-match. 54 > Run with --stacktrace option to get the stack trace. 55 > Run with --info or --debug option to get more log output. 56 > Run with --scan to get full insights. 57 > Get more help at https://help.gradle.org. 58 59 BUILD FAILED in 10s 60 ! ERROR: Failed to run Gradle! 61 We're sorry this build is failing. If you can't find the issue in application 62 code, please submit a ticket so we can help: https://help.heroku.com 63 You can also try reverting to the previous version of the buildpack by running: 64 $ heroku buildpacks:set https://github.com/heroku/heroku-buildpack-gradle#previous-version 65 66 Thanks, 67 Heroku 68 ! Push rejected, failed to compile Gradle app. 69 ! Push failed

該当のソースコード

build.gradle

1plugins { 2 id 'java' 3 id 'org.springframework.boot' version '3.2.4' 4 id 'io.spring.dependency-management' version '1.1.4' 5} 6 7group = 'com.example' 8version = '0.0.1-SNAPSHOT' 9 10java { 11 sourceCompatibility = '21' 12} 13 14configurations { 15 compileOnly { 16 extendsFrom annotationProcessor 17 } 18} 19 20repositories { 21 mavenCentral() 22} 23 24dependencies { 25 implementation 'org.springframework.boot:spring-boot-starter-jdbc' 26 implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' 27 implementation 'org.springframework.boot:spring-boot-starter-web' 28 compileOnly 'org.projectlombok:lombok' 29 developmentOnly 'org.springframework.boot:spring-boot-devtools' 30 runtimeOnly 'org.postgresql:postgresql' 31 annotationProcessor 'org.projectlombok:lombok' 32 testImplementation 'org.springframework.boot:spring-boot-starter-test' 33 implementation 'org.springframework.boot:spring-boot-starter-validation' 34 classpath 'org.springframework.boot:spring-boot-gradle-plugin:3.2.4.RELEASE' 35} 36 37tasks.named('test') { 38 useJUnitPlatform() 39} 40

試したこと・調べたこと

  • teratailやGoogle等で検索した
  • ソースコードを自分なりに変更した
  • 知人に聞いた
  • その他
上記の詳細・結果

下記のURLを参考にしました。
https://shinsuke789.hatenablog.jp/entry/2018/09/25/110000

https://stackoverflow.com/questions/76016825/could-not-resolve-all-files-for-configuration-classpath-android-studio-updat

補足

<開発環境>
PG:Java17.0.11
FW:Spring3.2.4(gradle8.7)
DB:postgresql12.18
IDE:eclipse2023-12 (4.30.0)

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

hfuob

2024/04/20 09:51

JDK21をインストールしましたが、同じエラーが表示されました。 C:\spring_workspace\workspace\kintai>java -version java version "21.0.3" 2024-04-16 LTS Java(TM) SE Runtime Environment (build 21.0.3+7-LTS-152) Java HotSpot(TM) 64-Bit Server VM (build 21.0.3+7-LTS-152, mixed mode, sharing)
hfuob

2024/04/21 01:19 編集

コメントありがとうございます。system.propertiesを試したところエラーが解決しました! ベストアンサーに選びたいので同じ内容を回答欄に投稿いただけますでしょうか? たぶん「あなたの回答」のところです。
KT001

2024/04/21 01:22

動いて良かったです!内容を回答欄の方に、投稿させて頂きました。
guest

回答1

0

ベストアンサー

Herokuに詳しくないのですが、OpenJDK 8 (1.8)で動いているように見えます。(Spring Boot 3はJDK17以上が必要となります)

Installing OpenJDK 1.8... done

https://devcenter.heroku.com/ja/articles/java-support#supported-java-versions

日本語版の方には記載がないのですが、OpenJDK 21も設定できるようです。
https://devcenter.heroku.com/articles/java-support#supported-java-versions


尚、Herokuの方は21で動いておりますでしょうか。もし、エラーメッセージに1.8や8などの文字が含まれているなら、Herokuの方がOpenJDK 8で動いている可能性があります。
https://devcenter.heroku.com/ja/articles/java-support#specifying-a-java-version
ファイル名: system.properties
java.runtime.version=21

投稿2024/04/21 01:21

編集2024/04/21 01:23
KT001

総合スコア618

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.47%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問