아무거나

[gradle] gradle을 이용한 통합 빌드 제공 본문

Java/Gradle & Maven

[gradle] gradle을 이용한 통합 빌드 제공

전봉근 2019. 10. 8. 16:24
반응형

아래와 같이 vuejs + springboot + gradle 프로젝트가 존재할 경우 vuejs(=client) 의 파일들을 빌드할 때 gradle 스크립트를 통하여 gradle명령 하나로 한번에 빌드하는 기능을 만들었다. 아래는 프로젝트의 구조이다.

spring-boot-vuejs
├─┬ server     → backend module with Spring Boot code
│ └── src
│      ├── main
│      └── resources
│            └── application.yml
├─┬ client    → frontend module with Vue.js code
│ ├── src
│ ├── config
│       └── index.js    → build path ( move: resources/templates/* )
└── build.gradle

 

위의 구조를 참고하여 gradle 통합 빌드 스크립트를 만들자.

https://github.com/srs/gradle-node-plugin (gradle node plugin을 사용)

 

[npm run build + gradle]
....

// Client Build Task
def clientPath = projectDir.toString() + '/../client'
def buildType = 'build'
task npmBuild(type: NpmTask) {
    workingDir = file(clientPath)
    args = ['run', buildType]
}

// Full Build
task fullBuild(type: Zip) {
    def tasks = [npmBuild, clean, build]
    for (int i = 0; i < tasks.size() - 1; i++) {
        tasks[i + 1].mustRunAfter(tasks[i])
    }
    dependsOn(tasks)
}

....

빌드는 gradle fullBuild 로 사용하자.

반응형
Comments