HomeAboutMeBlogGuest
© 2025 Sejin Cha. All rights reserved.
Built with Next.js, deployed on Vercel
🤩
개발
/
Java
Java
/
Gradle
Gradle
/
🎯
Getting Started
🎯

Getting Started

Build File BasicsDependency ManagementVersion CatalogDependency ConfigurationannotationProcessorTask basicsPlugin BasicsPlugin distribution

Build File Basics

  • Build Files (build.gradle)
    • 빌드 파일에는 2 종류의 의존성이 추가될 수 있음
        1. Gradle과 build script가 사용할 라이브러리와 plugin
        1. 프로젝트의 소스코드가 사용할 라이브러리
 

Dependency Management

[ Gradle ] Dependency Management Terminology. Artifact, Component 등의 용어들에 대한 정의
Gradle의 build script는 외부 의존성을 필요로 하는 프로젝트를 빌드하는 과정을 정의할 수 있음
외부 의존성의 가능한 종류 : Jar, plugins, libraries, source code

Version Catalog

version catalog는 의존성 선언을 중앙 집중화할 수 있게 해줌 (gradle 폴더 안의 libs.versions.toml 파일에)
version catalog의 4 섹션
  1. [versions] to declare the version numbers that plugins and libraries will reference.
  1. [libraries] to define the libraries used in the build files.
  1. [bundles] to define a set of dependencies.
  1. [plugins] to define plugins.
💡
근데 version catalog로 의존성을 중앙 집중화 하는 것 보다 root project에 build.gradle 파일 만든 후에 해당 파일에 subprojects 명령어로 공통 의존성 추가해주는 것이 더 나아보이는데..?
Managing Common Configuration

Dependency Configuration

Gradle 프로젝트에 적용되는 모든 dependency는 특정 scope를 갖고 적용이 됨
  • implementation
  • api
  • testImplementation
 
  • Custom Configuration : configurations 오브젝트로 프로젝트 configuration 을 관리할 수 있음. Configurations는 이름을 갖고, 서로서로를 확장할 수 있음
    • configurations { smokeTest.extendsFrom testImplementation } dependencies { testImplementation 'junit:junit:4.13' smokeTest 'org.apache.httpcomponents:httpclient:4.5.5' }
      Extending a configuration from another configuration
    • smokeTest는 HTTP call을 매번 실행하게 됨. 이 때 기반되는 test framework는 JUnit을 사용하기에 new configuration을 smokeTest로 정의하여 존재하는 test framework에 대한 의존성을 재활용하여 configuration을 이용할 수 있는 것

annotationProcessor

[ Intellij IDEA ] Configure annotation processors
[ Gradle ] Dependency management
Annotation Processing : 컴파일 타임에 annotation을 처리하여 코드를 생성하는 과정
dependency Configuration 중 annotationProcessor는 Java plugin에 의해 추가됨

Task basics

Tasks : 빌드가 수행하는 독립적인 단위의 작업 (e.g. compiling classes, creating a JAR, generating Javadoc ..)
  • 수행 가능한 task의 리스트를 보기 위한 명령어 : gradlew tasks

Plugin Basics

Plugin
  • Plugin은 build capability와 gradle의 customize를 위해 사용됨
  • 자바코드를 컴파일하는 기능같은 대부분의 기능들은 plugin 에 의해 추가됨
  • plugin을 apply함으로써 프로젝트와 Gradle이 할 수 있는 capability를 확장시킬 수 있는 것임
    • ↔ 플러그인이 project에서 사용할 수 있는 task를 더해줌, property와 method 또한 더해줌

Plugin distribution

플러그인은 3가지 방식으로 운용되고 있음
  • Core plugins — Gradle에서 개발하고 운영하는 core 플러그인
  • Community plugins — Gradle 커뮤니티가 공유하는 플러그인 (Gradle Plugin Portal로 이용가능)
  • Local plugins