나는 프로젝트를 여러개 하기 때문에 자바 버전이 다양하다 그래서 jdk 경로가 가끔씩은 프로젝트 java 버전에 따라 달라져야 한다
그런데 이 미친 vsCode는 gradle의 jdk 경로 인식을 잘 못한다 그래서 설정에서 바꿔 주는 방법을 적어 보았다.
vsCode 왼쪽위에 file > Rrefernes > settings 클릭
gradle 검색 > 메뉴의 Language Support for Java... 그러면 아래와 같은 항목이 뜨는데 빨간 네모에 있는 java home 두개에 아래의 칸에 jdk 경로를 넣어라(단 bin 폴더 이전까지의 경로이다 즉 bin 폴더를 선택하기 전에 경로) 그러면 하단우측에 파란색 버튼이 뜬다 아마도 재시작 버튼이였던 것 같다 클릭하거나 안뜬다면 vsCode 를 종료하고 다시 키면 gradle 가 java를 잘 찾는 것을 볼 수 있다.
학원이나, 공부할때나, 예전에 java 를 설치한 사람들은 이미 '환경변수' 에 java를 설정이되어 있을 것이다 그럴 경우 아래의 방법을 이용하라
https://velog.io/@jyp423/VSCode-Gradle-%EC%97%90%EB%9F%AC
아래의 메세지는 신경 쓰지 않아도 되지만 오류문구로 검색 하는 사람들을 위해 적어 놓았다 오류를 해석 하면 gradle에 설정된 java 버전과 프로젝트에서 설정한 java 버전이 다르다는 말이다
[info][gradle-server] Gradle Server started, listening on 62966
[info] Gradle client connected to server
[info] Java Home: C:\Users\KangDahyun.vscode\extensions\redhat.java-1.37.0-win32-x64\jre\17.0.13-win32-x86_64
[info] JVM Args: --add-opens=java.base/java.util=ALL-UNNAMED,--add-opens=java.base/java.lang=ALL-UNNAMED,--add-opens=java.base/java.lang.invoke=ALL-UNNAMED,--add-opens=java.prefs/java.util.prefs=ALL-UNNAMED,--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED,--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED,--add-opens=java.base/java.nio.charset=ALL-UNNAMED,--add-opens=java.base/java.net=ALL-UNNAMED,--add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED,-XX:MaxMetaspaceSize=384m,-XX:+HeapDumpOnOutOfMemoryError,-Xms256m,-Xmx512m,-Dfile.encoding=UTF-8,-Duser.country=KR,-Duser.language=ko,-Duser.variant
[info] Gradle User Home: C:\Users\KangDahyun.gradle
[info] Gradle Version: 8.10.1
[error] FAILURE: Build failed with an exception.
Failed to calculate the value of task ':compileJava' property 'javaCompiler'.
Cannot find a Java installation on your machine matching this tasks requirements: {languageVersion=21, vendor=any vendor, implementation=vendor-specific} for WINDOWS on x86_64.
No locally installed toolchains match and toolchain download repositories have not been configured.
Learn more about toolchain auto-detection at https://docs.gradle.org/8.10.1/userguide/toolchains.html#sec:auto_detection.
Learn more about toolchain repositories at https://docs.gradle.org/8.10.1/userguide/toolchains.html#sub:download_repositories.
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.
CONFIGURE FAILED in 9s
[error][gradle-server] The supplied build action failed with an exception.
[error] Error getting build for d:\DATA\git\POC\imgt-back: The supplied build action failed with an exception.
[info] Java Home: C:\Users\KangDahyun.vscode\extensions\redhat.java-1.37.0-win32-x64\jre\17.0.13-win32-x86_64
[info] JVM Args: --add-opens=java.base/java.util=ALL-UNNAMED,--add-opens=java.base/java.lang=ALL-UNNAMED,--add-opens=java.base/java.lang.invoke=ALL-UNNAMED,--add-opens=java.prefs/java.util.prefs=ALL-UNNAMED,--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED,--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED,--add-opens=java.base/java.nio.charset=ALL-UNNAMED,--add-opens=java.base/java.net=ALL-UNNAMED,--add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED,-XX:MaxMetaspaceSize=384m,-XX:+HeapDumpOnOutOfMemoryError,-Xms256m,-Xmx512m,-Dfile.encoding=UTF-8,-Duser.country=KR,-Duser.language=ko,-Duser.variant
[info] Gradle User Home: C:\Users\KangDahyun.gradle
[info] Gradle Version: 8.10.1
[error] FAILURE: Build failed with an exception.
Failed to calculate the value of task ':compileJava' property 'javaCompiler'.
Cannot find a Java installation on your machine matching this tasks requirements: {languageVersion=21, vendor=any vendor, implementation=vendor-specific} for WINDOWS on x86_64.
No locally installed toolchains match and toolchain download repositories have not been configured.
Learn more about toolchain auto-detection at https://docs.gradle.org/8.10.1/userguide/toolchains.html#sec:auto_detection.
Learn more about toolchain repositories at https://docs.gradle.org/8.10.1/userguide/toolchains.html#sub:download_repositories.
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.
CONFIGURE FAILED in 730ms
[error][gradle-server] The supplied build action failed with an exception.
[error] Error getting build for d:\DATA\git\POC\imgt-back: The supplied build action failed with an exception.
[info] Found 0 tasks