Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gradle 초기 설정 issue #1

Closed
kchung1995 opened this issue Feb 12, 2022 · 2 comments
Closed

Gradle 초기 설정 issue #1

kchung1995 opened this issue Feb 12, 2022 · 2 comments

Comments

@kchung1995
Copy link
Owner

kchung1995 commented Feb 12, 2022

아래 형식의 build.gradle 작성 시 Gradle이 성공적으로 빌드되지 않음.

buildscript {
    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'
apply plugin: 'io.spring.dependency-management'


group 'com.katfun.crudboard'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
}

dependencies {
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'

    compile('org.springframework.boot:spring-boot-starter-web')
    testCompile('org.springframework.boot:spring-boot-starter-test')
}

test {
    useJUnitPlatform()
}

에러 메세지:

Build file '/Users/kchung1995/IdeaProjects/CRUD-Web-Bulletin-Board/build.gradle' line: 14

Could not compile build file '/Users/kchung1995/IdeaProjects/CRUD-Web-Bulletin-Board/build.gradle'.
> startup failed:
  build file '/Users/kchung1995/IdeaProjects/CRUD-Web-Bulletin-Board/build.gradle': 14: only buildscript {} and other plugins {} script blocks are allowed before plugins {} blocks, no other statements are allowed
@kchung1995
Copy link
Owner Author

kchung1995 commented Feb 12, 2022

에러 메세지에 따르면 plugins {} 위에는 buildscript{}와 기타 plugin만 작성될 수 있다고 한다.
https://docs.gradle.org/5.4.1/userguide/plugins.html 를 보면, 다음과 같이 설명하고 있다.

The plugins {} block must also be a top level statement in the buildscript. It cannot be nested inside another construct (e.g. an if-statement or for-loop).

따라서 파일 내용을 아래와 같이 작성하였다.

buildscript {
    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'
apply plugin: 'io.spring.dependency-management'


group 'com.katfun.crudboard'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
}

dependencies {
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'

    compile('org.springframework.boot:spring-boot-starter-web')
    testCompile('org.springframework.boot:spring-boot-starter-test')
}

test {
    useJUnitPlatform()
}

@kchung1995
Copy link
Owner Author

kchung1995 commented Feb 12, 2022

위 내용대로 수정하였더니 아래와 같은 에러가 발생하였다.

A problem occurred evaluating root project 'crud_web_bulletinboard'.
> Could not find method bulidscript() for arguments [build_6mave1izxdxtjzaj6xhvh1c86$_run_closure1@6c9b3020] on root project 'crud_web_bulletinboard' of type org.gradle.api.Project.

이는 Gradle 7이 원인인 듯 하다 (https://www.inflearn.com/questions/237363).
gradle-wrapper.properties 의 내용을 바꾸었다.

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

이후 다시 실행하여 성공적으로 빌드되었다.

> Task :prepareKotlinBuildScriptModel UP-TO-DATE

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.7.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 36s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant