• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    미해결

jar build 동작 확인을 위한 Window cmd 이용 중 Build failed with an exception 오류

24.05.01 22:35 작성 조회수 101

0

질문 시에는 위 내용은 삭제하고 다음 내용을 남겨주세요.
=========================================
[질문 템플릿]
1. 강의 내용과 관련된 질문인가요? (예/아니오)
2. 인프런의 질문 게시판과 자주 하는 질문에 없는 내용인가요? (예/아니오)
3. 질문 잘하기 메뉴얼을 읽어보셨나요? (예/아니오)

[질문 내용]
H2 database Ctrl C 후
gradlew clean build 실행 시 아래와 같이 화면이 나타납니다.

이전에 시행했을땐 이런 오류가 떴습니다.
(base) C:\study\jpashop\jpashop>gradlew clean build

Welcome to Gradle 8.7!

Here are the highlights of this release:

  • Compiling and testing with Java 22

  • Cacheable Groovy script compilation

  • New methods in lazy collection properties

For more details see https://docs.gradle.org/8.7/release-notes.html

Starting a Gradle Daemon (subsequent builds will be faster)

Task :compileJava FAILED

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':compileJava'.

error: invalid source release: 21

  • Try:

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.

BUILD FAILED in 8s 2 actionable tasks: 2 executed

Gradle 8.7같은 경우 Java 22와 호환이 되어있는것 같은데 Java21로 설정하고 프로젝트를 진행 했을 때 어떻게 처리해야하는지 궁금합니다.

답변 1

답변을 작성해보세요.

0

인프런 AI 인턴님의 프로필

인프런 AI 인턴

2024.05.01

안녕하세요, 인프런 AI 인턴입니다.

박진재님의 jar build 관련 문제와 유사한 경우를 살펴본 결과, 질문자님이 겪고 계시는 오류는 “invalid source release: 21”로 컴파일 중 Java 소스 버전에 관련된 문제로 보입니다. 이번 경우, Gradle이 Java 22를 지원하면서 Java 21로 설정하여 발생한 문제로 추측됩니다. 이와 유사한 상황이나 문제를 해결한 기존 답변을 우선 추천드립니다.

  1. gradlew clean build 오류
    • 이 답변에서는 Java 버전과 Gradle 설정이 일치하지 않아 발생한 문제를 다루고 있습니다. JDK 버전과 build.gradle 파일 내의 sourceCompatibility 설정이 일치하는지 확인해야 합니다. 질문 내용과 비슷하게 invalid source release 에러가 발생한 상황이며, JDK를 새로 설치하거나 올바른 버전으로 설정 변경하는 것으로 해결되었습니다.

Java 기반 프로젝트에서 Gradle 또는 Maven과 같은 빌드 도구를 사용할 때, 올바른 Java 버전 설정은 매우 중요합니다. sourceCompatibility는 프로젝트가 사용하는 Java 소스 코드의 버전을 Gradle에 알려주어야 할 때 사용됩니다. JDK 버전과 이 설정이 일치하지 않을 때, 컴파일 에러가 발생할 수 있습니다.

현재 문제를 해결하기 위해서는 다음과 같은 방법을 제안드립니다:
1. JDK 버전 확인: 프로젝트에 맞는 JDK 버전이 설치되어 있는지 확인하세요.
2. 환경변수 확인: JAVA_HOME 환경변수가 올바른 JDK 경로로 설정되어 있는지 검토하세요.
3. Gradle 설정 확인: build.gradle 파일 내 sourceCompatibility 값을 현재 설치된 JDK 버전과 일치하게 수정하세요.

추가적으로 설정 후 IDE나 명령 프롬프트를 재시작하여 변경 사항을 적용하는 것을 잊지 마세요.

저는 질문자님의 이해를 돕고자 지식공유자님의 기존 답변을 참고하여 유사한 답변 링크를 추천해드리고 있습니다.
현재 베타 기능으로 답변이 만족스럽지 않을 수 있는 점 양해 부탁드립니다. 🙏
추가적으로 궁금한 점이 있으시면, 이어서 질문해 주세요. 곧 지식공유자께서 답변해 주실 것입니다.

박진재님의 프로필

박진재

질문자

2024.05.01

확인해보니까 Gradle 설정은 21로 해두었지만 jdk-17.0.8.101-hotspot이 기본 환경 변수로 설정되어있고 JDK21이 실제로 설치가 안되었을때는 직접설치하고 환경변수경로를 JDK21 경로로 바꿔줘야하는거죠?

David님의 프로필

David

2024.05.01

안녕하세요. 박진재님, 공식 서포터즈 David입니다.

네, 맞습니다.

감사합니다.

박진재님의 프로필

박진재

질문자

2024.05.01


저 오류 무시 후 build/libs 에 java -jar 파일도 실행해봤는데 아래와 같이 오류가떠서 이럴땐 어떻게 해야하는지 궁금합니다.

Error: -jar requires jar file specification

Usage: java [options] <mainclass> [args...]

(to execute a class)

or java [options] -jar <jarfile> [args...]

(to execute a jar file)

or java [options] -m <module>[/<mainclass>] [args...]

java [options] --module <module>[/<mainclass>] [args...]

(to execute the main class in a module)

or java [options] <sourcefile> [args]

(to execute a single source-file program)

Arguments following the main class, source file, -jar <jarfile>,

-m or --module <module>/<mainclass> are passed as the arguments to

main class.

where options include:

-cp <class search path of directories and zip/jar files>

-classpath <class search path of directories and zip/jar files>

--class-path <class search path of directories and zip/jar files>

A ; separated list of directories, JAR archives,

and ZIP archives to search for class files.

-p <module path>

--module-path <module path>...

A ; separated list of elements, each element is a file path

to a module or a directory containing modules. Each module is either

a modular JAR or an exploded-module directory.

--upgrade-module-path <module path>...

A ; separated list of elements, each element is a file path

to a module or a directory containing modules to replace

upgradeable modules in the runtime image. Each module is either

a modular JAR or an exploded-module directory.

--add-modules <module name>[,<module name>...]

root modules to resolve in addition to the initial module.

<module name> can also be ALL-DEFAULT, ALL-SYSTEM,

ALL-MODULE-PATH.

--enable-native-access <module name>[,<module name>...]

modules that are permitted to perform restricted native operations.

<module name> can also be ALL-UNNAMED.

--list-modules

list observable modules and exit

-d <module name>

--describe-module <module name>

describe a module and exit

--dry-run create VM and load main class but do not execute main method.

The --dry-run option may be useful for validating the

command-line options such as the module system configuration.

--validate-modules

validate all modules and exit

The --validate-modules option may be useful for finding

conflicts and other errors with modules on the module path.

-D<name>=<value>

set a system property

-verbose:[class|module|gc|jni]

enable verbose output for the given subsystem

-version print product version to the error stream and exit

--version print product version to the output stream and exit

-showversion print product version to the error stream and continue

--show-version

print product version to the output stream and continue

--show-module-resolution

show module resolution output during startup

-? -h -help

print this help message to the error stream

--help print this help message to the output stream

-X print help on extra options to the error stream

--help-extra print help on extra options to the output stream

-ea[:<packagename>...|:<classname>]

-enableassertions[:<packagename>...|:<classname>]

enable assertions with specified granularity

-da[:<packagename>...|:<classname>]

-disableassertions[:<packagename>...|:<classname>]

disable assertions with specified granularity

-esa | -enablesystemassertions

enable system assertions

-dsa | -disablesystemassertions

disable system assertions

-agentlib:<libname>[=<options>]

load native agent library <libname>, e.g. -agentlib:jdwp

see also -agentlib:jdwp=help

-agentpath:<pathname>[=<options>]

load native agent library by full pathname

-javaagent:<jarpath>[=<options>]

load Java programming language agent, see java.lang.instrument

-splash:<imagepath>

show splash screen with specified image

HiDPI scaled images are automatically supported and used

if available. The unscaled image filename, e.g. image.ext,

should always be passed as the argument to the -splash option.

The most appropriate scaled image provided will be picked up

automatically.

See the SplashScreen API documentation for more information

@argument files

one or more argument files containing options

--disable-@files

prevent further argument file expansion

--enable-preview

allow classes to depend on preview features of this release

To specify an argument for a long option, you can use --<name>=<value> or

--<name> <value>.

David님의 프로필

David

2024.05.02

gradle 버전을 8.5로 낮춘 뒤 다시 시도해 보시겠어요?
https://www.inflearn.com/questions/1251256/comment/336001