Error Record

[Java/자바] Could not resolve all files for configuration ':classpath'.

F12:) 2023. 7. 18. 19:40

오류 메세지

더보기

A problem occurred configuring root project 'demo'.
> Could not resolve all files for configuration ':classpath'.
   > Could not resolve org.springframework.boot:spring-boot-gradle-plugin:3.1.1.
     Required by:
         project : > org.springframework.boot:org.springframework.boot.gradle.plugin:3.1.1
      > No matching variant of org.springframework.boot:spring-boot-gradle-plugin:3.1.1 was found. The consumer was configured to find a library for use during runtime, compatible with Java 11, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '8.1.1' but:
          - Variant 'apiElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.1.1 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 11

(길어서 이 정도 까지만..)

 

해결 방법

스프링 프로젝트를 start.spring.io를 통해서 생성하고 압축을 해제한 후, IDE로 열어서 build를 하는 과정 중에서 발생한 오류이다.

메세지를 읽어보면 자세한 오류 내용이 나오는데, 요약하면 아래와 같다.

 

- Spring boot의 버전과 내 자바의 버전이 일치하지 않는다.

 

나는 Java 11을 쓰고 있었고, 스프링 부트 3.1.1로 프로젝트를 생성하였다.

 

하지만 찾아보니, 스프링부트 3.x 버전은 자바 17에서 사용 가능하다는 것이었다.

이를 위해 두 가지 해결방법이 있다.

 

1. 자바 버전을 17로 바꾼다.

2. 스프링 부트를 2.x로 생성한다.

 

나는 2번 방법을 사용하였다. 프로젝트를 스프링 부트 2.7.13 버전으로 다시 생성하여 빌드하니 문제 없었다.