Java & Spring

[Sprign Boot] Java와 Gradle 버전 맞추기

softserve 2024. 5. 23. 12:49
반응형

저는 Java 8을 사용 중입니다.

인텔리제이에서 스프링 부트 3.2.5 프로젝트를 생성한 뒤,

openjdk 22를 다운받아 Gradle 8.7로 빌드를 시도했으나 실패하고 말았습니다.

에러 메시지의 내용은 다음과 같습니다.

 

A problem occurred configuring root project 'blogdemo'.

Could not resolve all artifacts for configuration ':classpath'. Could not resolve org.springframework.boot:spring-boot-gradle-plugin:3.2.5. Required by: project : > org.springframework.boot:org.springframework.boot.gradle.plugin:3.2.5 No matching variant of org.springframework.boot:spring-boot-gradle-plugin:3.2.5 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:

  • Variant 'apiElements' declares a library, packaged as a jar, and its dependencies declared externally:
  • 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
  • Other compatible attribute:
  • Doesn't say anything about org.gradle.plugin.api-version (required '8.7')
  • Variant 'javadocElements' declares a component for use during runtime, and its dependencies declared externally:
  • Incompatible because this component declares documentation and the consumer needed a library
  • Other compatible attributes:
  • Doesn't say anything about its elements (required them packaged as a jar)
  • Doesn't say anything about its target Java version (required compatibility with Java 8)
  • Doesn't say anything about org.gradle.plugin.api-version (required '8.7')
  • Variant 'mavenOptionalApiElements' declares a library, packaged as a jar, and its dependencies declared externally:
  • 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
  • Other compatible attribute:
  • Doesn't say anything about org.gradle.plugin.api-version (required '8.7')
  • Variant 'mavenOptionalRuntimeElements' declares a library for use during runtime, packaged as a jar, and its dependencies declared externally:
  • Incompatible because this component declares a component, compatible with Java 17 and the consumer needed a component, compatible with Java 8
  • Other compatible attribute:
  • Doesn't say anything about org.gradle.plugin.api-version (required '8.7')
  • Variant 'runtimeElements' declares a library for use during runtime, packaged as a jar, and its dependencies declared externally:
  • Incompatible because this component declares a component, compatible with Java 17 and the consumer needed a component, compatible with Java 8
  • Other compatible attribute:
  • Doesn't say anything about org.gradle.plugin.api-version (required '8.7')
  • Variant 'sourcesElements' declares a component for use during runtime, and its dependencies declared externally:
  • Incompatible because this component declares documentation and the consumer needed a library
  • Other compatible attributes:
  • Doesn't say anything about its elements (required them packaged as a jar)
  • Doesn't say anything about its target Java version (required compatibility with Java 8)
  • Doesn't say anything about org.gradle.plugin.api-version (required '8.7')
  • Try:

Review the variant matching algorithm at https://docs.gradle.org/8.7/userguide/variant_attributes.html#sec:abm_algorithm. No matching variant errors are explained in more detail at https://docs.gradle.org/8.7/userguide/variant_model.html#sub:variant-no-match. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. Get more help at https://help.gradle.org.

 

부트 3 이상의 버전은 Java 17 이상 만을 지원하는데 기존에 Java 8이 설치되어 있었던 것이 영향이 있었나 봅니다.

자세히 보니 JDK를 선택할 때 openjdk22-java version 1.8이라고 되어 있네요. 인텔리제이에서 다운 받아서 그런 걸까요?

Oracle (https://www.oracle.com/kr/java/technologies/downloads/) 에서 JDK 22를 직접 다운받아 설치해 주니 Gradle 8.7로 정상적으로 빌드가 되는 것을 확인할 수 있었습니다.

Java 22 이상 버전은 아직 지원하지 않는다고 하는데 빌드가 되는 걸 보면 아직 Gradle docs 내용이 업데이트가 안 됐나 봅니다.

며칠 지나서 다시 해보니까 역시 안 됩니다. 아마 Java 버전을 계속 바꾸다 보니 변경된 것이 제대로 적용되지 않았던 것 같습니다. 왜 안 되지 싶을 때는 재부팅을 해보세요.

( https://docs.gradle.org/current/userguide/compatibility.html#java )

위 페이지에서 Java 버전별로 지원되는 Gradle 버전을 확인할 수 있습니다.

대표적인 것만 추려보면 다음과 같습니다.

Java  Support for toolchains  Support for running Gradle
8 - 2.0
11 - 5.0
17 7.3 7.3
21 8.4 8.5
22 8.7 -

 

*Gradle Toolchains는 여러 JDK 버전을 관리할 수 있는 기능이라고 하네요.

 

문제는 해결되었지만, 실험을 위해 Java 21을 설치한 다음 인텔리제이에서 Gradle이 사용할 JDK 버전을 바꿔보겠습니다.

 

인텔리제이 Gradle JVM 변경하기

 

Setting > Build, Execution, Deployment > Build Tools > Gradle

Gradle JVM에서 21 선택

 

 

Gradle 버전 변경하기

 

이번에는 Gradle 버전을 8.1로 바꿔줍니다.

gradle / wrapper / gradle-wrapper.properties를 열어

distributionUrl에서 gradle-8.5-bin.zip을 gradle-8.1-bin.zip로 수정

빌드를 해보면 다음과 같이 버전이 맞지 않는다는 에러 메시지를 확인할 수 있습니다. 

 

Unsupported Gradle JVM.

Your build is currently configured to use Java 21.0.3 and Gradle 8.1.

Possible solutions:

  • Use Java 19 as Gradle JVM: Open Gradle settings
  • Upgrade to Gradle 8.5 and re-sync

Gradle 버전을 다시 8.5로 돌리고 새로고침을 해보면 빌드가 성공한 것을 확인하실 수 있습니다.

 

 

 

 

 

반응형