IT/SpringBoot&AWS

[IntelliJ] Gradle Could not find method compile() 해결 방법

_하늘여우_ 2022. 5. 10. 13:29

출처 : 구글

 

참고도서: 스프링 부트와 AWS로 혼자 구현하는 웹 서비스

 

도서에서 인텔리제이 기반으로 gradle 프로젝트 생성을 안내하고 있는데, 

샘플 코드대로 작업했으나 오류가 발생하더라..

 

buildscript {
    // ext : build.gradle에서 사용하는 전역변수를 설정하겠다.
    // 여기서는 springBootVersion 전역변수를 생성하고 그 값을 '2.1.7.RELEASE' 로 하겠다는 의미.
    ext {
        springBootVersion = '2.1.9.RELEASE'
    }
    repositories {
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
//io.spring.dependency-management 플러그인은 스프링 부터의 의존성을 관리하는 플러그인
apply plugin: 'io.spring.dependency-management'

group 'com.jojoldu.book'
version '1.0.0-SNAPSHOT-'+new Date().format("yyyyMMddHHmmss")
sourceCompatibility = 1.8

repositories {
    mavenCentral()
    jcenter()
}

// dependencies : 프로젝트 개발에 필요한 의존성을 선언하는 곳.
dependencies {
    compile('org.springframework.boot:spring-boot-starter-web')
    testCompile('org.springframework.boot:spring-boot-starter-test')
}

 

A problem occurred evaluating root project 'freelec-springboot2-webservice'.
Could not find method compile() for arguments [org.springframework.boot:spring-boot-starter-web] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

 

문제는 dependencies 설정항목에 있었다.

compile() 메소드는 gradle 7.0 버전부터 '삭제'되었는데, 현재 gradle은 7.4 버전이라 에러가 발생하는 것이다.

dependecy configuration 의미 대체 값
compile 컴파일과 런타임 시 사용 implementation
testCompile 테스트 시에만 사용하는 속성 testImplementation
runtime 컴파일이 아닌 "런타임" 시에만 사용 runtimeOnly
testRuntime 테스트 시에만 사용하는 속성 testRuntimeOnly

 

gradle 7.0 이후 버전에서 위 메소드를 사용하고 에러가 발생하는 경우, 대체 congifuration으로 수정 후 재빌드를 해보자!

 

참고) gradle 버전 확인하기!
- gradle > wrapper > gradle-wrapper.properties 열기
- distributionUrl 에서 버전 확인
ex) distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip