Spring Boot 프로젝트 실행 오류

Bien·2023년 12월 28일
0

문제

스프링 부트를 공부한다고 회사에서 시간 날때 조금씩 연습한 코드가 있는데, 이걸 git clone으로 받아서 집에 있는 맥북으로 실행했을때 엄청난 길이의 에러 메세지가 발생하며 실행이 되지 않았다.

A problem occurred configuring root project 'servlet'.
Could not resolve all files for configuration ':classpath'.
Could not resolve org.springframework.boot:spring-boot-gradle-plugin:3.2.0.
Required by:
project : > org.springframework.boot:org.springframework.boot.gradle.plugin:3.2.0
No matching variant of org.springframework.boot:spring-boot-gradle-plugin:3.2.0 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.5' but:
- Variant 'apiElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.2.0 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
- Other compatible attribute:
- Doesn't say anything about org.gradle.plugin.api-version (required '8.5')
- Variant 'javadocElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.2.0 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 target Java version (required compatibility with Java 11)
- Doesn't say anything about its elements (required them packaged as a jar)
- Doesn't say anything about org.gradle.plugin.api-version (required '8.5')
- Variant 'mavenOptionalApiElements' capability org.springframework.boot:spring-boot-gradle-plugin-maven-optional:3.2.0 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
- Other compatible attribute:
- Doesn't say anything about org.gradle.plugin.api-version (required '8.5')
- Variant 'mavenOptionalRuntimeElements' capability org.springframework.boot:spring-boot-gradle-plugin-maven-optional:3.2.0 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 11
- Other compatible attribute:
- Doesn't say anything about org.gradle.plugin.api-version (required '8.5')
- Variant 'runtimeElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.2.0 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 11
- Other compatible attribute:
- Doesn't say anything about org.gradle.plugin.api-version (required '8.5')
- Variant 'sourcesElements' capability org.springframework.boot:spring-boot-gradle-plugin:3.2.0 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 target Java version (required compatibility with Java 11)
- Doesn't say anything about its elements (required them packaged as a jar)
- Doesn't say anything about org.gradle.plugin.api-version (required '8.5')

진짜 엄청길어서 눈에 잘 들어오지도 않았다.

내가 이번에 깃으로 클론 받은 프로젝트는 스프링부트 3.2.0를 사용하고 있었고, 스프링 부트 3.0 부터는 Java17부터 지원한다. 내 프로젝트가 구동이 안되는 이유는 바로 여기에 있었다.

해결

1. Java -version

해당 명령어로 내 자바 버전을 확인 했다.

JDK 버전이 11이다 🫠. 생각해보니 내 맥북으로는 테무린 11 버전으로 간단한 공부를 하고 있어서 이렇게 설정되어 있었다.

2. JDK 버전 수동으로 변경

나처럼 개발을 하다보면 JDK버전을 중간중간 변경해야할 때가 있을거다. (참고로 나는 macOS의 zsh쉘 환경에서 환경변수를 설정했다)
/usr/libexec/java_home -V
이 명령어를 사용해 설치된 Java Virtual Machines 목록을 확인 해본다.

...😳오지게도 많이 설치했다...

우선,
echo 'export JAVA_HOME=/usr/local/opt/openjdk@21' >> ~/.zshrc
해당 명령어를 실행한다.

export JAVA_HOME=/usr/local/opt/openjdk@21' : JAVA_HOME 환경 변수를 설정하는 명령다. 이 변수는 자바 설치 경로 즉 openjdk21이 설치된 위치를 나타낸다.
>> ~/.zshrc : 이 부분은 JAVA_HOME=/usr/local/opt/openjdk@21라는 문자열을 사용자의 홈 디렉토리에 있는 .zshrc 파일 끝에 추가하는 명령어이다. .zshrc는 zsh쉘의 환경 설정 파일로, 쉘을 시작할 때마다 실행된다.

다음으로는,
echo 'export PATH=$JAVA_HOME/bin:$PATH' >> ~/.zshrc 명령어를 실행한다.
export PATH=$JAVA_HOME/bin:$PATH : 이 명령어는 시스템의 실행 파일 경로에 Java의 bin 디렉토리를 추가해서 자바 실행 파일들이 시스템의 어디서나 실행될 수 있게 해준다.

이후,
source ~/.zshrc를 실행해 변경 사항을 저장해주면 된다.

위와 같이 쉘을 시작할 때마다 자동으로 자바 환경 변수를 설정하도록 해주는 명령어를 사용해 수동으로 JDK 버전을 변경 할 수 있다.

이렇게 까지 했는데도 빌드가 안되고 오류가 발생한다면 다른 설정을 확인해 봐야한다.

3. Gradle 설정 확인

build.gradle 파일을 확인하여 필요한 의존성이 올바르게 선언되었는지 확인한다.

이 부분을 확인해준다.

나는 여기까지 확인했는데도 오류가 있었다. 그럴 수 밖에 없지 인텔리제이도 기존에 설정된 자바 11로 프로젝트를 실행할테니까 ~ 아주 흥이다 😤

4. IntelliJ 설정 확인

IntelliJ의 Preferences/Settings -> Build, Execution, Deployment -> Build Tools -> Gradle 로 이동한다.

아래와 같은 설정중 Gradle의 JVM이 Java 17이상인지 확인한다.

그리고 다음으로 프로젝트 SDK의 버전을 확인하면 된다.
이번에는 file->Project Structure.. 로 이동해서 여기도 java 17 이상으로 설정해준다.

이렇게 적용을 끝내준다.

이후 Gradle Refresh를 하면 정상적으로 빌드가 되는 것을 확인 할 수 있다😌

profile
🙀

0개의 댓글