문제 사항

  • Gradle 프로젝트에 Spring REST Docs를 추가하여 프로젝트를 생성함
  • 그런데 Gradle에 asciidoctor와 관련된 plugin을 찾지 못했다는 오류가 발생함
    • plugin id: 'org.asciidoctor.convert' version: '2.2.1' was not found in any of the following sources
  • 이 문제를 해결하기 위해서 Gradle에 대해서 조사함
  • 최종적으로는 Gradle 버전과 asciidoctor 버전 간의 호환 문제였음

해결 방법

Build Automation

Build automation involves scripting or automating the process of compiling computer source code into binary code.

  • Build Automation이란 자동으로 source code를 binary code로 만드는 행위이다.
  • build automation을 위해서 script 언어를 사용할 수 있다.

Build란?

  • Build란 source code를 binary code로 만드는 행위이다.
  • 이때 build는 여러 과정을 거쳐서 이뤄질 수 있다.
  • 과정 하나 하나를 task라고 부르며, 이를 code를 통해서 명시할 수 있다.
  • 대표적인 task들
    • 컴퓨터 소스코드를 바이너리 코드로 컴파일 하기 (compile)
    • 바이너리 코드를 하나로 합치기 (package)
    • 자동으로 테스트 실행하기 (test)

Build Automation Tool

  • Util
    • Ant, Maven, Gradle

    • 주된 목적은 artifact를 생성하는 것

      💡 `artifact란?`
    • 특정 시점에 만들어낸 개발 산출물

    • ex) jar 또는 war 파일

  • Server
    • 웹 기반의 기술록서 build automation util을 스케줄 대로 실행하거나, trigger 기반으로 실행함

Gradle

  • 그래들(이하 Gradle)은 그루비(Groovy)를 기반으로 한 빌드 도구이다. Ant
    와 Maven과 같은 이전 세대 빌드 도구의 단점을 보완하고 장점을 취합하여 만든 오픈소스로 공개된 빌드 도구

Gradle 이전의 build tool

Ant

  • 장점
    • XML 기반으로 빌드 스크립트를 작성한다.
    • 자유롭게 빌드 단위를 지정할 수 있다.
    • 간단하고 사용하기 쉽다.
  • 단점
    • 유연하지만 프로젝트가 방대해지는 경우 스크립트 관리나 빌드 과정이 복잡해진다.
    • 생명주기(Lifecycle)을 갖지 않아 각각의 결과물에 대한 의존관계 등을 정의해야 한다.

Maven

  • 장점
    • XML 기반으로 작성한다.
    • 생명주기(Lifecycle)와 프로젝트 객체 모델(POM, Project Object Model)이란 개념이 도입됐다.
    • Ant의 장황한 빌드 스크립트를 개선했다.
    • pom.xml에 필요한 라이브러리를 선언하면 자동으로 해당 프로젝트로 불러와 편리하다.
  • 단점
    • 상대적으로 학습 장벽이 높다.
    • 라이브러리가 서로 의존하는 경우 복잡해질 수 있다.

Gradle V.S. Maven

  • 각각의 task마다 속도 비교를 하였는데 Gradle의 속도가 더 빠름
  • XML보다 Groovy가 더 가독성이 좋음
  • 이러한 점들이 Gradle이 Maven보다 좋음

Gradle의 특징

  • Gradle은 앞서 살펴본 Ant와 Maven이 가진 장점을 모아 만들었다. 의존성 관리를 위한 다양한 방법을 제공하고 빌드 스크립트를 XML 언어가 아닌 JVM에서 동작하는 스크립트 언어 ‘그루비’ 기반의 DSL(Domain Specific Language)를 사용한다.
  • 그루비(Groovy)는 자바 문법과 유사하여 자바 개발자가 쉽게 익힐 수 있는 장점이 있으며 Gradle Wrapper를 이용하면 Gradle이 설치되지 않은 시스템에서도 프로젝트를 빌드할 수 있다.
  • 심지어 메이븐(Maven)의 pom.xml을 Gradle 용으로 변환할 수도 있으며 Maven의 중앙 저장소도 지원하기 때문에 라이브러리를 모두 그대로 가져다 사용할 수 있다.

Gradle Wrapper란?

The Wrapper is a script that invokes a declared version of Gradle, downloading it beforehand if necessary. As a result, developers can get up and running with a Gradle project quickly without having to follow manual installation processes saving your company time and money.

  • 한 마디로 gradle이 깔리지 않은 상태에서 주어진 gradle 프로젝트를 실행해주는 script 파일이다.

Project Object Model (POM)

A Project Object Model or POM is the fundamental unit of work in Maven. It is an XML file that contains information about the project and configuration details used by Maven to build the project. It contains default values for most projects.

  • code를 이용하여 project의 설정을 포함한 메타 정보를 담아둔 파일이다. 그리하여 build 시에 해당 파일이 사용된다.

Gradle Task 사용해보기

tasl 구조

task 태스크이름 {
    ... 작업들
}
task sayHello {
    println 'Hello Taeng'
}

Gradle Plugin

정의

  • plugin은 task들의 집합이다.
    • 매번 같은 코드를 작성하면 비효율적이기에 이를 plugin으로 묶어두어 효율적으로 코드를 재사용한다.

실습

plugins {
	id 'com.android.apllication'
	id 'org.jetbrains.kotilin.android'
}
$ gradle tasks --all // 모든 Task 출력

Build tasks
-----------
app:assemble - Assemble main outputs for all the variants.
app:assembleAndroidTest - Assembles all the Test applications.
app:build - Assembles and tests this project.
app:buildDependents - Assembles and tests this project and all projects that depend on it.
app:buildNeeded - Assembles and tests this project and all projects it depends on.
app:bundle - Assemble bundles for all the variants.
app:clean - Deletes the build directory.
...

Other tasks
-----------
app:analyzeDebugAndroidTestDependencies
app:analyzeDebugDependencies
app:analyzeDebugUnitTestDependencies
app:analyzeReleaseDependencies
app:analyzeReleaseUnitTestDependencies
app:assembleDebug - Assembles main output for variant debug
app:assembleDebugAndroidTest - Assembles main output for variant debugAndroidTest
app:assembleDebugUnitTest - Assembles main output for variant debugUnitTest
app:assembleRelease - Assembles main output for variant release
app:assembleReleaseUnitTest - Assembles main output for variant releaseUnitTest
..

참고문헌

  1. https://velog.io/@max9106/Spring-Spring-rest-docs를-이용한-문서화
  2. https://velog.io/@minnseong/spring-rest-docs
  3. https://madplay.github.io/post/what-is-gradle
  4. https://docs.gradle.org/current/userguide/gradle_wrapper.html
  5. https://techblog.woowahan.com/2625/
profile
Try again, Fail again, Fail better

0개의 댓글